-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathworker-bundler-artifact.test.ts
More file actions
59 lines (50 loc) · 2.28 KB
/
Copy pathworker-bundler-artifact.test.ts
File metadata and controls
59 lines (50 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { describe, expect, it } from "@effect/vitest";
import { join } from "node:path";
import {
WORKER_BUNDLER_DIRNAME,
WORKER_BUNDLER_RUNTIME_FILES,
missingWorkerBundlerFiles,
} from "./worker-bundler-artifact";
const STAGED_DIR = join("/opt/executor/bin", WORKER_BUNDLER_DIRNAME);
/** An existence probe that reports only the given POSIX-relative paths. */
const staged =
(...relatives: readonly string[]) =>
(path: string): boolean =>
relatives.some((relative) => path === join(STAGED_DIR, ...relative.split("/")));
describe("missingWorkerBundlerFiles", () => {
it("reports nothing when the full artifact is staged", () => {
expect(missingWorkerBundlerFiles(STAGED_DIR, staged(...WORKER_BUNDLER_RUNTIME_FILES))).toEqual(
[],
);
});
it("reports every file when the directory is empty", () => {
expect(missingWorkerBundlerFiles(STAGED_DIR, () => false)).toEqual([
...WORKER_BUNDLER_RUNTIME_FILES,
]);
});
// The regression this whole seam exists for: the packaged daemon reads the
// wasm from disk beside the entry. A copy that brought the JS but dropped the
// wasm used to pass the build and fail on the user's machine at startup.
it("reports the esbuild wasm when only the JS entrypoints are staged", () => {
expect(
missingWorkerBundlerFiles(STAGED_DIR, staged("dist/index.js", "dist/index.bundled.js")),
).toEqual(["dist/esbuild.wasm"]);
});
// `index.bundled.js` is the file consumers load — the package's own
// `dist/index.js` still has bare imports nothing can resolve inside the
// compiled binary. Staging index.js alone is not enough.
it("reports the packed entry when only the unbundled package entry is staged", () => {
expect(
missingWorkerBundlerFiles(STAGED_DIR, staged("dist/index.js", "dist/esbuild.wasm")),
).toEqual(["dist/index.bundled.js"]);
});
it("names files relative to the staged directory so errors are quotable", () => {
for (const relative of WORKER_BUNDLER_RUNTIME_FILES) {
expect(relative.startsWith("dist/")).toBe(true);
}
});
it("requires the packed entry and the wasm, not just the package entry", () => {
expect(WORKER_BUNDLER_RUNTIME_FILES).toContain("dist/index.bundled.js");
expect(WORKER_BUNDLER_RUNTIME_FILES).toContain("dist/esbuild.wasm");
});
});