Fork Horse repository, listed by its owner. Publisher snapshot.
packages/forkhorse-gatekeeper/test/verify-bundle.ts
Snapshot at 34e3175
1import assert from "node:assert/strict";
2import { readFileSync } from "node:fs";
3import { createRequire } from "node:module";
4import { markIconUrl } from "../../forkhorse-dashboard/src/mark.ts";
5
6const { JSDOM, VirtualConsole } = createRequire(import.meta.url)("jsdom") as {
7 JSDOM: new (
8 html: string,
9 options?: { virtualConsole: unknown },
10 ) => { window: { document: Document; close(): void } };
11 VirtualConsole: new () => {
12 on(type: string, handler: (error: Error & { type?: string }) => void): unknown;
13 };
14};
15// jsdom does not parse CSS4 @layer/@property. Geometry and appearance are checked in the real browser.
16const virtualConsole = new VirtualConsole();
17virtualConsole.on("jsdomError", (error) => {
18 if (error.type !== "css parsing") throw error;
19});
20const options = { virtualConsole };
21const html = readFileSync(new URL("../dist/sidebar.html", import.meta.url), "utf8");
22const brand = JSON.parse(readFileSync(new URL("../../../brand.json", import.meta.url), "utf8"));
23const dom = new JSDOM(html, options);
24const document = dom.window.document;
25assert.equal(document.title, brand.name);
26assert.equal(document.querySelector('link[rel="icon"]')!.getAttribute("href"), markIconUrl(brand.mark));
27assert.equal(document.querySelectorAll('script[src],link[rel="stylesheet"]').length, 0);
28assert.equal(document.querySelectorAll("script").length, 2);
29assert.match(document.querySelector("script")!.textContent!, /prefers-color-scheme/);
30assert.ok(document.querySelector("style")!.textContent!.length > 1000, "dashboard CSS is inlined");
31assert.doesNotMatch(html, /Fixture update batch|LOCAL FIXTURE ONLY|git\.idiot\.tax/);
32assert.doesNotMatch(html, /\bprocess\.env\b/, "the sandboxed browser has no Node process global");
33assert.equal(document.getElementById("sidebar")!.dataset.fixture, undefined);
34assert.equal(document.querySelector("#sidebar [role=status]")!.textContent, `Loading ${brand.slug}…`);
35assert.match(document.querySelector("style")!.textContent!, /:root\{--font-sans/);
36console.log("Bundle verified: branded inline HTML, JavaScript and CSS; fixture data absent.");
37dom.window.close();
38const configurator = new JSDOM(
39 readFileSync(new URL("../dist/configurator.html", import.meta.url), "utf8"),
40 options,
41);
42assert.equal(configurator.window.document.title, brand.name);
43assert.equal(configurator.window.document.querySelector('link[rel="icon"]')!.getAttribute("href"), markIconUrl(brand.mark));
44assert.equal(
45 configurator.window.document.querySelectorAll('script[src],link[rel="stylesheet"]').length,
46 0,
47);
48assert.ok(configurator.window.document.querySelector("style")!.textContent!.length > 300);
49console.log("Configurator verified: self-contained draft-only frame.");
50configurator.window.close();
51const picker = new JSDOM(
52 readFileSync(new URL("../dist/picker.html", import.meta.url), "utf8"),
53 options,
54);
55assert.equal(picker.window.document.title, brand.name);
56assert.equal(picker.window.document.querySelector('link[rel="icon"]')!.getAttribute("href"), markIconUrl(brand.mark));
57assert.equal(
58 picker.window.document.querySelectorAll('script[src],link[rel="stylesheet"]').length,
59 0,
60);
61picker.window.close();
62const worker = readFileSync(new URL("../dist/worker.js", import.meta.url), "utf8");
63assert.doesNotMatch(
64 worker,
65 /fixture-agent-credential-only|LOCAL FIXTURE batch|This local fixture refuses/,
66);
67console.log("Picker verified; production Worker excludes offline fixture entrypoints.");
68