File size: 1,259 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import { beforeEach, describe, expect, it, vi } from "vitest";
const runCommandWithTimeout = vi.fn();
vi.mock("../../process/exec.js", () => ({
runCommandWithTimeout,
}));
const { createGlobalCommandRunner } = await import("./shared.js");
describe("createGlobalCommandRunner", () => {
beforeEach(() => {
vi.clearAllMocks();
runCommandWithTimeout.mockResolvedValue({
stdout: "",
stderr: "",
code: 0,
signal: null,
killed: false,
termination: "exit",
});
});
it("forwards argv/options and maps exec result shape", async () => {
runCommandWithTimeout.mockResolvedValueOnce({
stdout: "out",
stderr: "err",
code: 17,
signal: null,
killed: false,
termination: "exit",
});
const runCommand = createGlobalCommandRunner();
const result = await runCommand(["npm", "root", "-g"], {
timeoutMs: 1200,
cwd: "/tmp/openclaw",
env: { OPENCLAW_TEST: "1" },
});
expect(runCommandWithTimeout).toHaveBeenCalledWith(["npm", "root", "-g"], {
timeoutMs: 1200,
cwd: "/tmp/openclaw",
env: { OPENCLAW_TEST: "1" },
});
expect(result).toEqual({
stdout: "out",
stderr: "err",
code: 17,
});
});
});
|