import { mkdtemp, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { pathToFileURL } from "node:url"; import { build } from "../scripts/build.mjs"; import test from "node:test"; import assert from "node:assert/strict"; import { readFile, readdir } from "node:fs/promises"; import { fileURLToPath } from "node:url"; const root = fileURLToPath(new URL("../", import.meta.url)); test("production output contains every composed section and only runtime assets", async (t) => { const output = await mkdtemp(join(tmpdir(), "dualentry-build-")); t.after(() => rm(output, { recursive: true, force: true })); const generated = pathToFileURL(output + "/"); await build(output); const html = await readFile(new URL("index.html", generated), "utf8"); const sections = [...html.matchAll(/data-capture-section="([^"]+)"/g)].map( (x) => x[1], ); assert.deepEqual(sections, [ "hero", "workflow", "video", "selector", "agent", "prepared", "context", "progression", "stats", "modules", "closing", ]); assert.ok(!html.includes('class="eyebrow"')); assert.ok(!html.includes("data-view-choice")); assert.ok(!html.includes("data-step-choice")); const ids = [...html.matchAll(/\sid="([^"]+)"/g)].map((x) => x[1]); assert.equal( new Set(ids).size, ids.length, "IDs must be unique after composition", ); for (const match of html.matchAll(/(?:src|href)="([^"#]+)"/g)) { if (!match[1].startsWith("http")) await readFile( new URL( match[1].endsWith("/") ? match[1] + "index.html" : match[1], generated, ), ); } const files = await readdir(generated); for (const unwanted of [ "sections", "tests", "captures", "README.md", ".vercel", ]) assert.ok(!files.includes(unwanted)); assert.ok(!html.includes("")); for (const file of files.filter((name) => name.endsWith(".css"))) { const css = await readFile(new URL(file, generated), "utf8"); assert.equal( (css.match(/\/\*/g) || []).length, (css.match(/\*\//g) || []).length, `${file} has unbalanced comments`, ); assert.ok( !css.replace(/\/\*[\s\S]*?\*\//g, "").includes("/*"), `${file} has an unterminated comment`, ); } });