import { chromium } from '/Users/simon-pierreboucher/Desktop/uqo-eval/node_modules/playwright/index.mjs'; // The satelliteindex dev server port is read from .next/dev/lock (8310 may be taken by another project on this machine). import { readFileSync } from 'node:fs'; let port = process.env.PORT ?? '8310'; try { port = String(JSON.parse(readFileSync(new URL('../.next/dev/lock', import.meta.url), 'utf8')).port ?? port); } catch { /* fall back */ } const BASE = `http://localhost:${port}`; console.log(`QA against ${BASE}`); const 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']; const OUT = '/Users/simon-pierreboucher/Desktop/Projets/apps-web/satelliteindex/apps/web/qa/screens/entities'; const browser = await chromium.launch(); let failures = 0; for (const width of [390, 1440]) { const ctx = await browser.newContext({ viewport: { width, height: width === 390 ? 844 : 900 }, deviceScaleFactor: 1 }); for (const p of PAGES) { const page = await ctx.newPage(); const errors = []; page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); }); page.on('pageerror', (e) => errors.push(`pageerror: ${e.message}`)); const t0 = Date.now(); const res = await page.goto(BASE + p, { waitUntil: 'networkidle', timeout: 120000 }); const status = res?.status(); const { sw, iw, h1 } = await page.evaluate(() => ({ sw: document.documentElement.scrollWidth, iw: window.innerWidth, h1: document.querySelector('h1')?.textContent?.trim() })); const name = p.replace(/^\//, '').replace(/[\/?=&]+/g, '_') || 'root'; await page.screenshot({ path: `${OUT}/${name}-${width}.png`, fullPage: true }); const overflow = sw > iw; const expect404 = p.includes('does-not-exist'); // A 404 document legitimately logs "Failed to load resource … 404" — that is the expected status, not a page error. const realErrors = expect404 ? errors.filter((e) => !/status of 404/.test(e)) : errors; const bad = overflow || realErrors.length || (!expect404 && status !== 200) || (expect404 && status !== 404); if (bad) failures++; 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(' | ') : ''}`); await page.close(); } await ctx.close(); } await browser.close(); process.exit(failures ? 1 : 0);