refactor: dedupe cli config cron and install flows
This commit is contained in:
@@ -41,6 +41,28 @@ function createMockChild(params?: { code?: number; signal?: NodeJS.Signals | nul
|
||||
return child;
|
||||
}
|
||||
|
||||
type SpawnCall = [string, string[], Record<string, unknown>];
|
||||
|
||||
type ExecCall = [
|
||||
string,
|
||||
string[],
|
||||
Record<string, unknown>,
|
||||
(err: Error | null, stdout: string, stderr: string) => void,
|
||||
];
|
||||
|
||||
function expectCmdWrappedInvocation(params: {
|
||||
captured: SpawnCall | ExecCall | undefined;
|
||||
expectedComSpec: string;
|
||||
}) {
|
||||
if (!params.captured) {
|
||||
throw new Error("expected command wrapper to be called");
|
||||
}
|
||||
expect(params.captured[0]).toBe(params.expectedComSpec);
|
||||
expect(params.captured[1].slice(0, 3)).toEqual(["/d", "/s", "/c"]);
|
||||
expect(params.captured[1][3]).toContain("pnpm.cmd --version");
|
||||
expect(params.captured[2].windowsVerbatimArguments).toBe(true);
|
||||
}
|
||||
|
||||
describe("windows command wrapper behavior", () => {
|
||||
afterEach(() => {
|
||||
spawnMock.mockReset();
|
||||
@@ -59,16 +81,8 @@ describe("windows command wrapper behavior", () => {
|
||||
try {
|
||||
const result = await runCommandWithTimeout(["pnpm", "--version"], { timeoutMs: 1000 });
|
||||
expect(result.code).toBe(0);
|
||||
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);
|
||||
const captured = spawnMock.mock.calls[0] as SpawnCall | undefined;
|
||||
expectCmdWrappedInvocation({ captured, expectedComSpec });
|
||||
} finally {
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
@@ -91,21 +105,8 @@ describe("windows command wrapper behavior", () => {
|
||||
|
||||
try {
|
||||
await runExec("pnpm", ["--version"], 1000);
|
||||
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);
|
||||
const captured = execFileMock.mock.calls[0] as ExecCall | undefined;
|
||||
expectCmdWrappedInvocation({ captured, expectedComSpec });
|
||||
} finally {
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user