forked from heygen-com/hyperframes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.producer.test.ts
More file actions
86 lines (75 loc) · 2.56 KB
/
Copy pathvite.producer.test.ts
File metadata and controls
86 lines (75 loc) · 2.56 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { resolve } from "node:path";
import { describe, expect, it, vi } from "vitest";
import {
createRetryingModuleLoader,
ensureProducerDist,
resolveProducerDistEntry,
resolveWorkspaceRoot,
} from "./vite.producer";
describe("ensureProducerDist", () => {
it("does nothing when the producer dist entry already exists", () => {
const exec = vi.fn();
const result = ensureProducerDist({
studioDir: "/repo/packages/studio",
existsSyncImpl: () => true,
execFileSyncImpl: exec as never,
});
expect(result).toEqual({
built: false,
producerDistEntry: resolve("/repo/packages/producer/dist/index.js"),
});
expect(exec).not.toHaveBeenCalled();
});
it("builds producer when the dist entry is missing", () => {
const exec = vi.fn();
const env = { TEST: "1" } as NodeJS.ProcessEnv;
const result = ensureProducerDist({
studioDir: "/repo/packages/studio",
existsSyncImpl: () => false,
execFileSyncImpl: exec as never,
env,
});
expect(result).toEqual({
built: true,
producerDistEntry: resolve("/repo/packages/producer/dist/index.js"),
});
expect(exec).toHaveBeenCalledWith(
"bun",
["run", "--filter", "@hyperframes/producer", "build"],
{
cwd: resolve("/repo"),
stdio: "pipe",
env,
},
);
});
});
describe("producer path helpers", () => {
it("resolves the producer dist entry relative to studio", () => {
expect(resolveProducerDistEntry("/repo/packages/studio")).toBe(
resolve("/repo/packages/producer/dist/index.js"),
);
});
it("resolves the workspace root relative to studio", () => {
expect(resolveWorkspaceRoot("/repo/packages/studio")).toBe(resolve("/repo"));
});
});
describe("createRetryingModuleLoader", () => {
it("retries after an initial load failure instead of caching the rejection", async () => {
const load = vi
.fn<() => Promise<string>>()
.mockRejectedValueOnce(new Error("boom"))
.mockResolvedValueOnce("ok");
const getModule = createRetryingModuleLoader(load);
await expect(getModule()).rejects.toThrow("boom");
await expect(getModule()).resolves.toBe("ok");
expect(load).toHaveBeenCalledTimes(2);
});
it("reuses the same promise after a successful load", async () => {
const load = vi.fn<() => Promise<string>>().mockResolvedValue("ok");
const getModule = createRetryingModuleLoader(load);
await expect(getModule()).resolves.toBe("ok");
await expect(getModule()).resolves.toBe("ok");
expect(load).toHaveBeenCalledTimes(1);
});
});