/** * The theme setting is one string that four files have to agree about, and * three of them cannot import the one that defines it. * * theme.ts writes "light" or "dark" under a key in localStorage. Base.astro's * inline script reads that key before the first paint — inline, so it cannot * import anything, so the key is spelled out twice. styles.css is what turns * the resulting attribute into colours. Change any one of the three and * nothing errors: the toggle keeps working for the rest of the session and * has simply stopped surviving a reload, or stopped changing anything at all. * * Run with `npm test`. */ import { test } from "node:test"; import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import { join } from "node:path"; const web = join(new URL(".", import.meta.url).pathname, ".."); const read = (path) => readFile(join(web, path), "utf8"); const theme = await read("src/theme.ts"); const layout = await read("src/layouts/Base.astro"); const css = await read("src/styles.css"); const account = await read("src/account.ts"); const key = theme.match(/STORE_KEY = "([^"]+)"/)?.[1]; assert.ok(key, "theme.ts no longer declares STORE_KEY as a literal"); test("the inline script reads the key theme.ts writes", () => { const inline = layout.slice(layout.indexOf("