justintsus-experiment Public
// Screenshots of both builds' rendered list pages at 1280 and 390 px, light and dark, plus the help// popover opened by keyboard, and a horizontal-overflow and DESIGN.md check per page.import { createRequire } from "node:module";import { mkdirSync, writeFileSync } from "node:fs";const require = createRequire(`${process.env.WORKTREE_A}/package.json`);const { chromium } = require("playwright-core");const OUT = new URL("../shots-all", import.meta.url).pathname;mkdirSync(OUT, { recursive: true });const PORT = { A: 8811, B: 8812 };const PAGES = ["issues-default", "issues-query", "issues-invalid", "issues-page2", "pulls-default", "pulls-invalid", "pulls-query"];const browser = await chromium.launch();const report = {};for (const k of ["A", "B"]) { for (const width of [1280, 390]) { for (const scheme of ["light", "dark"]) { const ctx = await browser.newContext({ viewport: { width, height: 900 }, colorScheme: scheme, deviceScaleFactor: 1 }); const page = await ctx.newPage(); for (const name of PAGES) { await page.goto(`http://127.0.0.1:${PORT[k]}/${name}.html`, { waitUntil: "networkidle" }); const info = await page.evaluate(() => { const doc = document.documentElement; const q = document.querySelector('input[name="q"]'); const errs = [...document.querySelectorAll(".search-errors li")].map((li) => li.textContent.trim().slice(0, 140)); const marks = [...document.querySelectorAll(".search-errors mark")].map((m) => { const cs = getComputedStyle(m); return { text: m.textContent.slice(0, 40), deco: cs.textDecorationLine + " " + cs.textDecorationStyle, color: cs.color }; }); const fonts = new Set([...document.querySelectorAll(".search-help summary, .search-errors, .pr-search input")].map((e) => getComputedStyle(e).fontFamily.split(",")[0] + " " + getComputedStyle(e).fontWeight)); const upper = [...document.querySelectorAll(".search-errors *, .search-help *")].filter((e) => getComputedStyle(e).textTransform === "uppercase").length; const grads = [...document.querySelectorAll(".search-errors, .search-help, .search-help *, .search-errors *")].filter((e) => /gradient/.test(getComputedStyle(e).backgroundImage)).length; const emdash = /—/.test((document.querySelector("main")?.innerText) ?? ""); return { scrollW: doc.scrollWidth, clientW: doc.clientWidth, overflow: doc.scrollWidth > doc.clientWidth, input: q?.value, invalid: q?.getAttribute("aria-invalid"), describedby: q?.getAttribute("aria-describedby"), errs, marks, fonts: [...fonts], upper, grads, emdash }; }); report[`${k} ${name} ${width} ${scheme}`] = info; await page.screenshot({ path: `${OUT}/${k}-${name}-${width}-${scheme}.png`, fullPage: true }); } // help popover: open by keyboard (Tab to the summary, Enter), screenshot for (const name of ["issues-default", "pulls-default"]) { await page.goto(`http://127.0.0.1:${PORT[k]}/${name}.html`, { waitUntil: "networkidle" }); await page.focus(".search-help > summary"); await page.keyboard.press("Enter"); const open = await page.evaluate(() => ({ open: document.querySelector(".search-help").open, rows: [...document.querySelectorAll(".search-help code")].map((c) => c.textContent), overflow: document.documentElement.scrollWidth > document.documentElement.clientWidth })); report[`${k} ${name}-help ${width} ${scheme}`] = open; await page.screenshot({ path: `${OUT}/${k}-${name}-help-${width}-${scheme}.png`, fullPage: false }); } await ctx.close(); } } // without JavaScript: the details still opens const ctx = await browser.newContext({ javaScriptEnabled: false, viewport: { width: 1280, height: 900 } }); const page = await ctx.newPage(); await page.goto(`http://127.0.0.1:${PORT[k]}/issues-default.html`); await page.click(".search-help > summary"); report[`${k} nojs-help`] = await page.locator(".search-help").evaluate((d) => d.open); await ctx.close();}await browser.close();writeFileSync(`${OUT}/report.json`, JSON.stringify(report, null, 1));console.log("done");