diff --git a/src/process/exec.windows.test.ts b/src/process/exec.windows.test.ts index 8b171ffebf0..10405a735ed 100644 --- a/src/process/exec.windows.test.ts +++ b/src/process/exec.windows.test.ts @@ -51,23 +51,24 @@ describe("windows command wrapper behavior", () => { it("wraps .cmd commands via cmd.exe in runCommandWithTimeout", async () => { const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32"); const expectedComSpec = process.env.ComSpec ?? "cmd.exe"; - let captured: { command: string; args: string[]; options: Record } | null = - null; spawnMock.mockImplementation( - (command: string, args: string[], options: Record) => { - captured = { command, args, options }; - return createMockChild(); - }, + (_command: string, _args: string[], _options: Record) => createMockChild(), ); try { const result = await runCommandWithTimeout(["pnpm", "--version"], { timeoutMs: 1000 }); expect(result.code).toBe(0); - expect(captured?.command).toBe(expectedComSpec); - expect(captured?.args.slice(0, 3)).toEqual(["/d", "/s", "/c"]); - expect(captured?.args[3]).toContain("pnpm.cmd --version"); - expect(captured?.options.windowsVerbatimArguments).toBe(true); + const captured = spawnMock.mock.calls[0] as + | [string, string[], Record] + | undefined; + if (!captured) { + throw new Error("spawn mock was not called"); + } + expect(captured[0]).toBe(expectedComSpec); + expect(captured[1].slice(0, 3)).toEqual(["/d", "/s", "/c"]); + expect(captured[1][3]).toContain("pnpm.cmd --version"); + expect(captured[2].windowsVerbatimArguments).toBe(true); } finally { platformSpy.mockRestore(); } @@ -76,27 +77,35 @@ describe("windows command wrapper behavior", () => { it("uses cmd.exe wrapper with windowsVerbatimArguments in runExec for .cmd shims", async () => { const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32"); const expectedComSpec = process.env.ComSpec ?? "cmd.exe"; - let captured: { command: string; args: string[]; options: Record } | null = - null; execFileMock.mockImplementation( ( - command: string, - args: string[], - options: Record, + _command: string, + _args: string[], + _options: Record, cb: (err: Error | null, stdout: string, stderr: string) => void, ) => { - captured = { command, args, options }; cb(null, "ok", ""); }, ); try { await runExec("pnpm", ["--version"], 1000); - expect(captured?.command).toBe(expectedComSpec); - expect(captured?.args.slice(0, 3)).toEqual(["/d", "/s", "/c"]); - expect(captured?.args[3]).toContain("pnpm.cmd --version"); - expect(captured?.options.windowsVerbatimArguments).toBe(true); + const captured = execFileMock.mock.calls[0] as + | [ + string, + string[], + Record, + (err: Error | null, stdout: string, stderr: string) => void, + ] + | undefined; + if (!captured) { + throw new Error("execFile mock was not called"); + } + expect(captured[0]).toBe(expectedComSpec); + expect(captured[1].slice(0, 3)).toEqual(["/d", "/s", "/c"]); + expect(captured[1][3]).toContain("pnpm.cmd --version"); + expect(captured[2].windowsVerbatimArguments).toBe(true); } finally { platformSpy.mockRestore(); }