import assert from "node:assert/strict"; import { readFile, readdir, lstat } from "node:fs/promises"; import { Script } from "node:vm"; const root = new URL("../", import.meta.url); const site = new URL("website/", root); const pkg = JSON.parse(await readFile(new URL("package.json", root), "utf8")); const html = await readFile(new URL("index.html", site), "utf8"); assert.ok(!/\u2014|—|&#(?:8212|x2014);/i.test(html), "The website must not contain em dashes"); // Only the public landing page is uploaded; workspace reports must never enter it. const files = await readdir(site); assert.deepEqual(files.sort(), [".nojekyll", "CNAME", "index.html"]); for (const file of files) assert.ok((await lstat(new URL(file, site))).isFile(), `Unexpected site object: ${file}`); const domain = (await readFile(new URL("CNAME", site), "utf8")).trim(); assert.equal(new URL(pkg.homepage).hostname, domain); assert.ok(html.includes(``), "Website version differs from package.json"); assert.ok(html.includes(`Version ${pkg.version}.`), "Website description version is stale"); assert.ok(html.includes(`
Version
${pkg.version}
`), "Website facts version is stale"); for (const version of html.match(/\bv\d+\.\d+\.\d+(?:-[\w.]+)?/g) || []) assert.equal(version, `v${pkg.version}`, "Visible website version is stale"); assert.ok(html.includes(``)); assert.ok(html.includes('')); assert.ok(!/<(?:script|img|iframe|link)\b[^>]*(?:src|href)=["'](?:https?:)?\/\//i.test( html.replace(/]*rel="canonical"[^>]*>/gi, "")), "The single-file site must not depend on remote assets"); const ids = [...html.matchAll(/\bid="([^"]+)"/g)].map(match => match[1]); assert.equal(new Set(ids).size, ids.length, "Duplicate page IDs"); const pages = [...html.matchAll(/\bdata-page="([^"]+)"/g)].map(match => match[1]); assert.equal(new Set(pages).size, pages.length, "Duplicate routed views"); assert.deepEqual(pages.sort(), ["about", "commands", "evidence", "faq", "guide", "home", "not-found", "roadmap", "search"]); for (const [, page] of html.matchAll(/\bdata-nav="([^"]+)"/g)) assert.ok(pages.includes(page), `Unknown navigation view: ${page}`); assert.ok(html.includes('