39 lines
1.8 KiB
JavaScript
39 lines
1.8 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import assert from "node:assert/strict";
|
|
import { describe, it } from "vitest";
|
|
|
|
const scriptSource = fs.readFileSync(path.join(path.dirname(new URL(import.meta.url).pathname), "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("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*"node20"/);
|
|
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\.TOOLCTRL_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("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.doesNotMatch(scriptSource, /packages:\s*"external"/);
|
|
});
|
|
});
|