const { strict: assert } = require("node:assert"); const fs = require("node:fs"); const path = require("node:path"); const modules = { paths: [path.resolve(__dirname, "../../../../job-tracker-ui")], }; const { chromium } = require(require.resolve("playwright", modules)); const axePath = require.resolve("axe-core/axe.min.js", modules); const base = process.env.JOBJAKT_GALLERY_URL || "http://127.0.0.1:4327"; async function scan() { const browser = await chromium.launch(); const results = []; try { const page = await browser.newPage(); const errors = []; page.on("pageerror", (error) => errors.push(error.message)); for (const concept of "ABCDE") { for (const width of [1440, 390]) { const lang = width === 390 ? "nb" : "en"; const theme = width === 390 ? "dark" : "light"; await page.setViewportSize({ width, height: 900 }); for (const screen of ["home", "discover", "detail", "cv"]) { await page.goto( base + "/?" + new URLSearchParams({ concept, screen, lang, theme }), ); await page.addScriptTag({ path: axePath }); const violations = await page.evaluate(async () => { const result = await axe.run(document, { runOnly: { type: "tag", values: ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"], }, }); return result.violations.map((v) => ({ rule: v.id, impact: v.impact, nodes: v.nodes.map((n) => ({ target: n.target, reason: n.failureSummary, })), })); }); results.push({ concept, width, screen, lang, theme, violations }); } } } fs.writeFileSync( path.join(__dirname, "accessibility.json"), JSON.stringify({ results, errors }, null, 2) + "\n", ); const failed = results.filter((x) => x.violations.length); console.log( results.length + " scans, " + failed.length + " states with findings, " + errors.length + " browser errors", ); assert.equal(errors.length, 0); assert.equal( failed.length, 0, "See accessibility.json for unresolved findings.", ); } finally { await browser.close(); } } scan().catch((error) => { console.error(error); process.exitCode = 1; });