import { pathToFileURL } from "node:url"; import { mkdtemp, readFile, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { writeTechLogServingArtifact } from "../../scripts/lib/tech-log-serving-artifact.ts"; const roots: string[] = []; afterEach(async () => { await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true }))); }); describe("TechLog serving artifact", () => { it("emits a self-contained deployment server and its route contract", async () => { const root = await mkdtemp(path.join(tmpdir(), "tech-log-serving-artifact-")); roots.push(root); const contract = { schemaVersion: 1 as const, publicSpaPaths: ["/", "/projects/auth-lab"], studioPathPrefix: "/studio" as const, studioSpaPathPatterns: ["^/studio$"], notFound: { status: 404 as const, contentType: "text/plain;charset=UTF-8" as const, body: "Not Found" as const, }, }; await writeTechLogServingArtifact({ distRoot: root, contract }); expect( JSON.parse( await readFile(path.join(root, "tech-log-serving-contract.json"), "utf8"), ), ).toEqual(contract); const serverModule = await import( `${pathToFileURL(path.join(root, "server.mjs")).href}?test=${Date.now()}` ); expect(serverModule.createTechLogProductionServer).toEqual(expect.any(Function)); }); });