/** * Core pages QA (real API): routes × widths → screenshots + checks (overflow, console errors, failed requests, * tap targets < 44 px on phones, "undefined/NaN/null" text). Output: qa/screens/core/-.png + report.json. * * node qa/core-qa.mjs [BASE_URL] [--quick] [--routes=/a,/b] [--widths=390,1440] */ import { chromium } from '/Users/simon-pierreboucher/Desktop/uqo-eval/node_modules/playwright/index.mjs'; import { mkdirSync, writeFileSync } from 'node:fs'; const args = process.argv.slice(2); const quick = args.includes('--quick'); const BASE = args.find((a) => a.startsWith('http')) ?? process.env.BASE_URL ?? 'http://localhost:8290'; const routesArg = args.find((a) => a.startsWith('--routes=')); const widthsArg = args.find((a) => a.startsWith('--widths=')); const OUT = new URL('./screens/core/', import.meta.url).pathname; mkdirSync(OUT, { recursive: true }); const ROUTES = routesArg ? routesArg.slice('--routes='.length).split(',') : ['/', '/countries/canada', '/compare/canada/australia', '/compare/canada/united-states/france?tab=economy', '/rankings/gdp-per-capita', '/indicators/life-expectancy', '/regions/g7', '/regions/compare', '/peers', '/changes']; const WIDTHS = widthsArg ? widthsArg.slice('--widths='.length).split(',').map(Number) : quick ? [390, 1440] : [320, 360, 375, 390, 430, 768, 1440, 1920]; const slug = (p) => (p === '/' ? 'home' : p.slice(1).replace(/[/?=&]+/g, '_')); const report = []; const browser = await chromium.launch(); for (const width of WIDTHS) { const mobile = width < 768; const ctx = await browser.newContext({ viewport: { width, height: mobile ? 844 : 900 }, deviceScaleFactor: 1, isMobile: mobile, hasTouch: mobile }); const page = await ctx.newPage(); const errors = []; const failed = []; page.on('pageerror', (e) => errors.push(`pageerror: ${String(e).slice(0, 200)}`)); page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text().slice(0, 200)); }); page.on('response', (r) => { if (r.status() >= 400 && r.url().includes('/api/')) failed.push(`${r.status()} ${r.url().slice(0, 140)}`); }); for (const path of ROUTES) { let status = 0; try { const resp = await page.goto(BASE + path, { waitUntil: 'networkidle', timeout: 90_000 }); status = resp?.status() ?? 0; } catch (e) { report.push({ path, width, status: 'ERR', error: String(e).slice(0, 200) }); continue; } await page.evaluate(() => document.fonts.ready); await page.evaluate(async () => { const h = document.documentElement.scrollHeight; for (let y = 0; y < h; y += 700) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 50)); } window.scrollTo(0, 0); }); await page.waitForLoadState('networkidle').catch(() => {}); await page.waitForTimeout(500); const m = await page.evaluate( ({ mobile }) => { const de = document.documentElement; const overflow = de.scrollWidth - de.clientWidth; const wide = [...document.querySelectorAll('body *')] .filter((el) => el.getBoundingClientRect().right > de.clientWidth + 1 && el.getBoundingClientRect().width > 0) .slice(0, 5) .map((el) => `${el.tagName.toLowerCase()}.${String(el.className).split(' ').slice(0, 3).join('.')} right=${Math.round(el.getBoundingClientRect().right)}`); const vis = (el) => { const r = el.getBoundingClientRect(); if (!r.width || !r.height) return false; const cs = getComputedStyle(el); return cs.visibility !== 'hidden' && cs.display !== 'none'; }; const small = mobile ? [...document.querySelectorAll('a,button,[role=button],input,select,summary,[role=radio],[role=tab]')] .filter(vis) .filter((el) => !el.closest('svg') && el.getBoundingClientRect().height < 44 && el.getBoundingClientRect().width < 44) .map((el) => `${el.tagName.toLowerCase()} "${(el.getAttribute('aria-label') || el.textContent || '').trim().slice(0, 30)}" ${Math.round(el.getBoundingClientRect().width)}x${Math.round(el.getBoundingClientRect().height)}`) : []; const text = document.body.innerText || ''; const bad = []; for (const re of [/\bundefined\b/g, /\bNaN\b/g, /(? {}); report.push({ path, width, status, ...m, errors: errors.splice(0), failed: failed.splice(0), file }); writeFileSync(OUT + 'report.json', JSON.stringify(report, null, 2)); } await ctx.close(); } await browser.close(); let fails = 0; for (const r of report) { const flags = []; if (r.status !== 200) flags.push(`HTTP ${r.status}`); if (r.overflow > 0) flags.push(`OVERFLOW +${r.overflow}px`); if (r.nSmall) flags.push(`${r.nSmall} small targets`); if (r.bad?.length) flags.push(`BAD TEXT ${r.bad.length}`); if (r.errors?.length) flags.push(`${r.errors.length} console errors`); if (r.failed?.length) flags.push(`${r.failed.length} failed API`); if (r.credits === false) flags.push('NO CREDITS'); if (flags.length) fails++; console.log(`${String(r.width).padStart(4)} ${r.path.padEnd(52)} ${flags.join(' · ') || 'ok'} (h=${r.docH})`); if (r.wide?.length) console.log(' wide:', r.wide.join(' | ')); if (r.small?.length) console.log(' small:', r.small.slice(0, 5).join(' | ')); if (r.bad?.length) console.log(' bad:', r.bad.join(' | ')); if (r.errors?.length) console.log(' errors:', r.errors.slice(0, 3).join(' | ')); if (r.failed?.length) console.log(' failed:', r.failed.slice(0, 3).join(' | ')); } console.log(`\n${report.length} renders, ${fails} with flags`);