Skip to content

Commit 967238e

Browse files
committed
Fix tests
1 parent 7bfa8bd commit 967238e

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"dist": true // set this to false to include "dist" folder in search results
1010
},
1111
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
12-
"typescript.tsc.autoDetect": "off"
12+
"typescript.tsc.autoDetect": "off",
13+
"vitest.disableWorkspaceWarning": true
1314
}

src/core/task/__tests__/Task.spec.ts

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,43 @@ vi.mock("execa", () => ({
3030
execa: vi.fn(),
3131
}))
3232

33-
vi.mock("fs/promises", () => ({
34-
mkdir: vi.fn().mockResolvedValue(undefined),
35-
writeFile: vi.fn().mockResolvedValue(undefined),
36-
readFile: vi.fn().mockImplementation((filePath) => {
37-
if (filePath.includes("ui_messages.json")) {
38-
return Promise.resolve(JSON.stringify(mockMessages))
39-
}
40-
if (filePath.includes("api_conversation_history.json")) {
41-
return Promise.resolve(
42-
JSON.stringify([
43-
{
44-
role: "user",
45-
content: [{ type: "text", text: "historical task" }],
46-
ts: Date.now(),
47-
},
48-
{
49-
role: "assistant",
50-
content: [{ type: "text", text: "I'll help you with that task." }],
51-
ts: Date.now(),
52-
},
53-
]),
54-
)
55-
}
56-
return Promise.resolve("[]")
57-
}),
58-
unlink: vi.fn().mockResolvedValue(undefined),
59-
rmdir: vi.fn().mockResolvedValue(undefined),
60-
}))
33+
vi.mock("fs/promises", async (importOriginal) => {
34+
const actual = (await importOriginal()) as Record<string, any>
35+
const mockFunctions = {
36+
mkdir: vi.fn().mockResolvedValue(undefined),
37+
writeFile: vi.fn().mockResolvedValue(undefined),
38+
readFile: vi.fn().mockImplementation((filePath) => {
39+
if (filePath.includes("ui_messages.json")) {
40+
return Promise.resolve(JSON.stringify(mockMessages))
41+
}
42+
if (filePath.includes("api_conversation_history.json")) {
43+
return Promise.resolve(
44+
JSON.stringify([
45+
{
46+
role: "user",
47+
content: [{ type: "text", text: "historical task" }],
48+
ts: Date.now(),
49+
},
50+
{
51+
role: "assistant",
52+
content: [{ type: "text", text: "I'll help you with that task." }],
53+
ts: Date.now(),
54+
},
55+
]),
56+
)
57+
}
58+
return Promise.resolve("[]")
59+
}),
60+
unlink: vi.fn().mockResolvedValue(undefined),
61+
rmdir: vi.fn().mockResolvedValue(undefined),
62+
}
63+
64+
return {
65+
...actual,
66+
...mockFunctions,
67+
default: mockFunctions,
68+
}
69+
})
6170

6271
vi.mock("p-wait-for", () => ({
6372
default: vi.fn().mockImplementation(async () => Promise.resolve()),

0 commit comments

Comments
 (0)