|
|
|
|
@ -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<string, unknown> } | null =
|
|
|
|
|
null;
|
|
|
|
|
|
|
|
|
|
spawnMock.mockImplementation(
|
|
|
|
|
(command: string, args: string[], options: Record<string, unknown>) => {
|
|
|
|
|
captured = { command, args, options };
|
|
|
|
|
return createMockChild();
|
|
|
|
|
},
|
|
|
|
|
(_command: string, _args: string[], _options: Record<string, unknown>) => 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<string, unknown>]
|
|
|
|
|
| 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<string, unknown> } | null =
|
|
|
|
|
null;
|
|
|
|
|
|
|
|
|
|
execFileMock.mockImplementation(
|
|
|
|
|
(
|
|
|
|
|
command: string,
|
|
|
|
|
args: string[],
|
|
|
|
|
options: Record<string, unknown>,
|
|
|
|
|
_command: string,
|
|
|
|
|
_args: string[],
|
|
|
|
|
_options: Record<string, unknown>,
|
|
|
|
|
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<string, unknown>,
|
|
|
|
|
(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();
|
|
|
|
|
}
|
|
|
|
|
|