Skip to content

Commit 252a255

Browse files
committed
fix: make header command quoting tests cross-platform
Extract quoteCommand into shared platform utils and use it in cliExec and cliConfig tests so assertions match Windows double quotes vs Unix single quotes.
1 parent ee9f912 commit 252a255

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

test/unit/cliConfig.test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from "@/settings/cli";
1515

1616
import { MockConfigurationProvider } from "../mocks/testHelpers";
17-
import { isWindows } from "../utils/platform";
17+
import { quoteCommand } from "../utils/platform";
1818

1919
vi.mock("node:os");
2020

@@ -320,9 +320,3 @@ describe("cliConfig", () => {
320320
});
321321
});
322322
});
323-
324-
function quoteCommand(value: string): string {
325-
// Used to escape environment variables in commands. See `getHeaderArgs` in src/headers.ts
326-
const quote = isWindows() ? '"' : "'";
327-
return `${quote}${value}${quote}`;
328-
}

test/unit/core/cliExec.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from "path";
44
import { beforeAll, describe, expect, it, vi } from "vitest";
55

66
import { MockConfigurationProvider } from "../../mocks/testHelpers";
7-
import { isWindows, writeExecutable } from "../../utils/platform";
7+
import { isWindows, quoteCommand, writeExecutable } from "../../utils/platform";
88

99
import type { CliEnv } from "@/core/cliExec";
1010

@@ -147,7 +147,7 @@ describe("cliExec", () => {
147147
"--url",
148148
"http://localhost:3000",
149149
"--header-command",
150-
"'my-header-cmd'",
150+
quoteCommand("my-header-cmd"),
151151
"speedtest",
152152
"owner/workspace",
153153
"--output",
@@ -192,7 +192,7 @@ describe("cliExec", () => {
192192
"--url",
193193
"http://localhost:3000",
194194
"--header-command",
195-
"'my-header-cmd'",
195+
quoteCommand("my-header-cmd"),
196196
"support",
197197
"bundle",
198198
"owner/workspace",

test/utils/platform.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ export function shimExecFile<
101101
return Object.assign({}, mod, { execFile });
102102
}
103103

104+
/**
105+
* Wraps a value in the platform-appropriate quote character,
106+
* matching the escaping in {@link getHeaderArgs} from src/settings/headers.ts.
107+
*/
108+
export function quoteCommand(value: string): string {
109+
const quote = isWindows() ? '"' : "'";
110+
return `${quote}${value}${quote}`;
111+
}
112+
104113
export function expectPathsEqual(actual: string, expected: string) {
105114
expect(normalizePath(actual)).toBe(normalizePath(expected));
106115
}

0 commit comments

Comments
 (0)