import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import assert from "node:assert/strict"; import { describe, it } from "vitest"; const scriptSource = fs.readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), "build-web-server.mjs"), "utf8"); describe("build-web-server", () => { it("bundles the server entrypoint into the production runtime artifact", () => { assert.match(scriptSource, /server\/server\.ts/); assert.match(scriptSource, /build\/server-runtime\/server\.js/); }); it("precompresses emitted client assets at build time", () => { assert.match(scriptSource, /precompressWebAssets/); assert.match(scriptSource, /pruneUnreferencedDuplicateCss/); assert.match(scriptSource, /clientBuildDirectory,\s*["']assets["']/); assert.match(scriptSource, /\["build", "build-portal"\]/); assert.match(scriptSource, /apps["'],\s*["']web["'],\s*buildDirectory,\s*["']client/); }); it("pins a Node ESM esbuild output instead of a runtime tsx command", () => { assert.match(scriptSource, /platform:\s*"node"/); assert.match(scriptSource, /format:\s*"esm"/); assert.match(scriptSource, /target:\s*"node24"/); assert.match(scriptSource, /sourcemap:\s*buildSourcemapsEnabled/); assert.match(scriptSource, /logLevel:\s*"warning"/); assert.doesNotMatch(scriptSource, /tsx/); }); it("keeps server sourcemaps opt-in through the documented env contract", () => { assert.match(scriptSource, /const buildSourcemapsEnabled\s*=/); assert.match(scriptSource, /process\.env\.HIVEGRID_BUILD_SOURCEMAPS\s*===\s*"1"/); assert.match(scriptSource, /process\.env\.SOURCEMAP\s*===\s*"true"/); assert.match(scriptSource, /process\.env\.BUILD_SOURCEMAPS\s*===\s*"true"/); assert.doesNotMatch(scriptSource, /sourcemap:\s*true/); }); it("embeds the public browser endpoints used by the authenticated CSP", () => { assert.match(scriptSource, /VITE_SENTRY_DSN_WEB/); assert.match(scriptSource, /VITE_OTEL_EXPORTER_OTLP_ENDPOINT/); assert.match(scriptSource, /VITE_HOCUSPOCUS_URL/); assert.match(scriptSource, /define:\s*browserCspBuildEnvDefines/); }); it("keeps runtime packages external to avoid bundling browser or native assets", () => { assert.match(scriptSource, /externalizeRuntimeDependencies/); assert.match(scriptSource, /plugins:\s*\[externalizeRuntimeDependencies\]/); assert.match(scriptSource, /function isExternalRuntimePackage/); assert.match(scriptSource, /specifier === "react-router"/); assert.match(scriptSource, /specifier === "@prisma\/adapter-pg"/); assert.match(scriptSource, /specifier === "pg"/); assert.doesNotMatch(scriptSource, /packages:\s*"external"/); }); });