/** * Platform pages QA: /stories, one story, /download, /updates, /api at 320/390/768/1440. * Checks: HTTP 200, no horizontal overflow, no console errors, tap targets ≥ 44 px on phones, no "undefined/NaN". * Screenshots → qa/screens/platform/-.png, report → qa/screens/platform/report.json. * node qa/platform-qa.mjs [BASE_URL] */ import { chromium } from '/Users/simon-pierreboucher/Desktop/uqo-eval/node_modules/playwright/index.mjs'; import { mkdirSync, writeFileSync } from 'node:fs'; const BASE = process.argv[2] ?? process.env.BASE_URL ?? 'http://localhost:8290'; const OUT = new URL('./screens/platform/', import.meta.url).pathname; mkdirSync(OUT, { recursive: true }); const ROUTES = ['/stories', '/stories/the-world-is-getting-older', '/stories/shifting-centre-of-the-world-economy', '/download', '/download?countries=canada,france&indicators=gdp,life-expectancy&from=2000', '/updates', '/api']; const WIDTHS = [320, 390, 768, 1440]; const slug = (p) => 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 = []; 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)); }); 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 vis = (el) => { const r = el.getBoundingClientRect(); if (r.width === 0 || r.height === 0) return false; const cs = getComputedStyle(el); return cs.visibility !== 'hidden' && cs.display !== 'none'; }; 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 targets = [...document.querySelectorAll('a,button,[role=button],input,select,summary,[role=radio],[role=tab]')].filter(vis); const small = mobile ? targets.filter((el) => el.getBoundingClientRect().height < 44 && el.getBoundingClientRect().width < 44).map((el) => `${el.tagName.toLowerCase()} "${(el.getAttribute('aria-label') || el.textContent || '').trim().slice(0, 30)}"`) : []; const text = document.body.innerText || ''; const bad = []; for (const re of [/\bundefined\b/g, /\bNaN\b/g]) { let mm; while ((mm = re.exec(text))) bad.push(`${mm[0]} @ "${text.slice(Math.max(0, mm.index - 40), mm.index + 30).replace(/\s+/g, ' ')}"`); } const footer = document.querySelector('footer')?.innerText ?? ''; const credits = /Simon-Pierre Boucher/.test(footer) && /contact@spboucher\.ai/.test(footer) && /MacLustr/.test(footer); return { overflow, wide, nSmall: small.length, small: small.slice(0, 6), bad, credits, title: document.title, h: de.scrollHeight }; }, { mobile }, ); const file = `${slug(path)}-${width}.png`; await page.screenshot({ path: OUT + file, fullPage: true }).catch(() => {}); report.push({ path, width, status, ...m, errors: errors.splice(0), file }); } await ctx.close(); } await browser.close(); writeFileSync(OUT + 'report.json', JSON.stringify(report, null, 2)); 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.credits === false) flags.push('NO CREDITS'); if (flags.length) fails++; console.log(`${String(r.width).padStart(4)} ${r.path.padEnd(70)} ${flags.join(' · ') || 'ok'} (h=${r.h})`); if (r.wide?.length) console.log(' wide:', r.wide.join(' | ')); if (r.small?.length) console.log(' small:', r.small.join(' | ')); if (r.bad?.length) console.log(' bad:', r.bad.join(' | ')); if (r.errors?.length) console.log(' errors:', r.errors.slice(0, 3).join(' | ')); } console.log(`\n${report.length} renders, ${fails} with flags`);