SPB Git forge
3commits 1branches 0releases
417.0 KBsize
maindefault branch
10 days agolast push
TypeScript 66.5% Python 30.9% JavaScript 1.4% CSS 0.7%
2.6 KB · 38 lines javascript
Raw Blame History
1import { chromium } from '/Users/simon-pierreboucher/Desktop/uqo-eval/node_modules/playwright/index.mjs';2// The satelliteindex dev server port is read from .next/dev/lock (8310 may be taken by another project on this machine).3import { readFileSync } from 'node:fs';4let port = process.env.PORT ?? '8310';5try { port = String(JSON.parse(readFileSync(new URL('../.next/dev/lock', import.meta.url), 'utf8')).port ?? port); } catch { /* fall back */ }6const BASE = `http://localhost:${port}`;7console.log(`QA against ${BASE}`);8const PAGES = ['/constellations', '/constellations?sort=activity&service=navigation', '/constellation/starlink', '/constellation/gps', '/operators', '/operators?kind=agency&q=nasa', '/operator/spacex', '/operator/nasa', '/countries', '/countries?sort=debris', '/country/canada', '/country/china', '/constellation/does-not-exist'];9const OUT = '/Users/simon-pierreboucher/Desktop/Projets/apps-web/satelliteindex/apps/web/qa/screens/entities';10const browser = await chromium.launch();11let failures = 0;12for (const width of [390, 1440]) {13  const ctx = await browser.newContext({ viewport: { width, height: width === 390 ? 844 : 900 }, deviceScaleFactor: 1 });14  for (const p of PAGES) {15    const page = await ctx.newPage();16    const errors = [];17    page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); });18    page.on('pageerror', (e) => errors.push(`pageerror: ${e.message}`));19    const t0 = Date.now();20    const res = await page.goto(BASE + p, { waitUntil: 'networkidle', timeout: 120000 });21    const status = res?.status();22    const { sw, iw, h1 } = await page.evaluate(() => ({ sw: document.documentElement.scrollWidth, iw: window.innerWidth, h1: document.querySelector('h1')?.textContent?.trim() }));23    const name = p.replace(/^\//, '').replace(/[\/?=&]+/g, '_') || 'root';24    await page.screenshot({ path: `${OUT}/${name}-${width}.png`, fullPage: true });25    const overflow = sw > iw;26    const expect404 = p.includes('does-not-exist');27    // A 404 document legitimately logs "Failed to load resource … 404" — that is the expected status, not a page error.28    const realErrors = expect404 ? errors.filter((e) => !/status of 404/.test(e)) : errors;29    const bad = overflow || realErrors.length || (!expect404 && status !== 200) || (expect404 && status !== 404);30    if (bad) failures++;31    console.log(`${bad ? 'FAIL' : 'ok  '} ${width}px ${p} status=${status} scrollWidth=${sw}/${iw} ${Date.now() - t0}ms h1="${h1}"${errors.length ? '\n     console: ' + errors.slice(0, 3).join(' | ') : ''}`);32    await page.close();33  }34  await ctx.close();35}36await browser.close();37process.exit(failures ? 1 : 0);38