import assert from "node:assert/strict"; import { access, readFile } from "node:fs/promises"; import test from "node:test"; const templateRoot = new URL("../", import.meta.url); async function render() { const workerUrl = new URL("../dist/server/index.js", import.meta.url); workerUrl.searchParams.set("test", `${process.pid}-${Date.now()}`); const { default: worker } = await import(workerUrl.href); return worker.fetch( new Request("http://localhost/", { headers: { accept: "text/html" }, }), { ASSETS: { fetch: async () => new Response("Not found", { status: 404 }), }, }, { waitUntil() {}, passThroughOnException() {}, }, ); } test("server-renders the product selector site", async () => { const response = await render(); assert.equal(response.status, 200); assert.match(response.headers.get("content-type") ?? "", /^text\/html\b/i); const html = await response.text(); assert.match(html, /高徳乐 AI 舵机选型助手/); assert.match(html, /243/); assert.match(html, /286/); assert.match(html, /精密齿轮配件/); assert.doesNotMatch(html, /Your site is taking shape|react-loading-skeleton|codex-preview/i); }); test("keeps starter preview infrastructure out of production", async () => { const [page, layout, packageJson] = await Promise.all([ readFile(new URL("../app/page.tsx", import.meta.url), "utf8"), readFile(new URL("../app/layout.tsx", import.meta.url), "utf8"), readFile(new URL("../package.json", import.meta.url), "utf8"), ]); assert.doesNotMatch(page, /SkeletonPreview|codex-preview|_sites-preview/); assert.doesNotMatch(layout, /codex-preview|_sites-preview|Starter Project/); assert.doesNotMatch(packageJson, /react-loading-skeleton/); await assert.rejects( access(new URL("public/_sites-preview", templateRoot)), ); });