import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { describe, it } from "node:test"; import { DEVICE_PANEL_CSS } from "../../ui/devicePanel.ts"; import { ONBOARDING_CSS } from "../../ui/onboarding.ts"; import { TOUCH_TARGET_PX } from "../../ui/tokens.ts"; function read(relative: string): string { return readFileSync(new URL(`../../../${relative}`, import.meta.url), "utf8"); } const html = read("index.html"); /** * The stylesheet with its own prose removed. * * Every structural assertion below runs against this rather than the raw file, * for two reasons that both bit once while writing it: a CSS comment quoting a * selector reads as that selector to a line scanner, and a comment containing a * `}` truncates any "slice to the closing brace" rule-body extraction. The raw * text is still used for the z-index assertion, deliberately — that one is meant * to be as literal as the `grep` in the build spec. */ const css = html.replace(/\/\*[\s\S]*?\*\//g, ""); /** Any `z-index: 4`-shaped declaration. A `var(--z-…)` reference is not one. */ const RAW_Z_INDEX = /z-index:\s*\d/g; describe("the stylesheet", () => { it("writes no raw z-index outside the :root token block", () => { const start = html.indexOf(":root {"); const end = html.indexOf("\n }", start); const outside = html.slice(0, start) + html.slice(end); const found = outside.match(RAW_Z_INDEX) ?? []; assert.deepEqual( found, [], `index.html writes ${found.length} raw z-index literal(s) outside :root — use var(--z-…)`, ); }); it("writes no raw z-index in any of the four injected stylesheets", () => { // These four modules mount a `