import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import test from "node:test"; import { THEME_STORAGE_KEY, isThemePreference, themePreferenceBootScript, } from "../src/lib/theme-preference.ts"; const layout = readFileSync(new URL("../src/app/layout.tsx", import.meta.url), "utf8"); const menu = readFileSync(new URL("../src/components/theme-preference-menu.tsx", import.meta.url), "utf8"); const sidebar = readFileSync(new URL("../src/components/app-sidebar.tsx", import.meta.url), "utf8"); const lib = readFileSync(new URL("../src/lib/theme-preference.ts", import.meta.url), "utf8"); const globalStyles = readFileSync(new URL("../src/app/globals.css", import.meta.url), "utf8"); test("only the three preferences are accepted", () => { for (const value of ["system", "light", "dark"]) assert.equal(isThemePreference(value), true); for (const value of ["", "Dark", "auto", null, undefined, 0, {}]) { assert.equal(isThemePreference(value), false); } }); test("the boot script runs before paint and only ever pins light or dark", () => { // "system" is the absence of data-theme — that is what the CSS media query // reads. Writing data-theme="system" would match neither dark block. assert.match(layout, /