forked from triggerdotdev/trigger.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreams.test.ts
More file actions
64 lines (56 loc) · 1.91 KB
/
streams.test.ts
File metadata and controls
64 lines (56 loc) · 1.91 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
import { describe, it, expect, vi, beforeEach } from "vitest";
import { streams } from "./streams.js";
import { taskContext, realtimeStreams } from "@trigger.dev/core/v3";
vi.mock("@trigger.dev/core/v3", async (importOriginal) => {
const original = await importOriginal<typeof import("@trigger.dev/core/v3")>();
return {
...original,
taskContext: {
ctx: {
run: {
id: "run_123",
// parentTaskRunId and rootTaskRunId are undefined for root tasks
},
},
},
realtimeStreams: {
pipe: vi.fn().mockReturnValue({
wait: () => Promise.resolve(),
stream: new ReadableStream(),
}),
},
};
});
describe("streams.pipe consistency", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("should not throw and should use self runId when target is 'root' in a root task", async () => {
const mockStream = new ReadableStream();
// This should not throw anymore
const { waitUntilComplete } = streams.pipe("test-key", mockStream, {
target: "root",
});
expect(realtimeStreams.pipe).toHaveBeenCalledWith(
"test-key",
mockStream,
expect.objectContaining({
target: "run_123",
})
);
});
it("should not throw and should use self runId when target is 'parent' in a root task", async () => {
const mockStream = new ReadableStream();
// This should not throw anymore
const { waitUntilComplete } = streams.pipe("test-key", mockStream, {
target: "parent",
});
expect(realtimeStreams.pipe).toHaveBeenCalledWith(
"test-key",
mockStream,
expect.objectContaining({
target: "run_123",
})
);
});
});