Skip to content

Commit 9f78da5

Browse files
committed
test(windows): mock fallback launch in schtasks install tests
1 parent 6c6c21b commit 9f78da5

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/daemon/schtasks.install.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ const schtasksResponses: { code: number; stdout: string; stderr: string }[] = []
1313
// `finally` block deletes the temp file. Indexed by the position in
1414
// `schtasksCalls` so individual tests can pin which create-call they assert on.
1515
const xmlPayloadCaptures: Array<{ index: number; xml: string }> = [];
16+
const childUnref = vi.hoisted(() => vi.fn());
17+
const spawn = vi.hoisted(() => vi.fn(() => ({ unref: childUnref })));
18+
19+
vi.mock("node:child_process", async () => {
20+
const actual = await vi.importActual<typeof import("node:child_process")>("node:child_process");
21+
return { ...actual, spawn };
22+
});
1623

1724
vi.mock("./schtasks-exec.js", () => ({
1825
execSchtasks: async (argv: string[]) => {
@@ -39,6 +46,9 @@ beforeEach(() => {
3946
schtasksCalls.length = 0;
4047
schtasksResponses.length = 0;
4148
xmlPayloadCaptures.length = 0;
49+
childUnref.mockReset();
50+
spawn.mockReset();
51+
spawn.mockImplementation(() => ({ unref: childUnref }));
4252
});
4353

4454
describe("installScheduledTask", () => {

0 commit comments

Comments
 (0)