mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 12:41:42 +00:00
refactor(test): reuse base CLI program mocks
This commit is contained in:
@@ -1,25 +1,9 @@
|
|||||||
import * as fs from "node:fs/promises";
|
import * as fs from "node:fs/promises";
|
||||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { parseCameraSnapPayload, parseCameraClipPayload } from "./nodes-camera.js";
|
import { parseCameraSnapPayload, parseCameraClipPayload } from "./nodes-camera.js";
|
||||||
|
import { callGateway, installBaseProgramMocks, runTui, runtime } from "./program.test-mocks.js";
|
||||||
|
|
||||||
const messageCommand = vi.fn();
|
installBaseProgramMocks();
|
||||||
const statusCommand = vi.fn();
|
|
||||||
const configureCommand = vi.fn();
|
|
||||||
const configureCommandWithSections = vi.fn();
|
|
||||||
const setupCommand = vi.fn();
|
|
||||||
const onboardCommand = vi.fn();
|
|
||||||
const callGateway = vi.fn();
|
|
||||||
const runChannelLogin = vi.fn();
|
|
||||||
const runChannelLogout = vi.fn();
|
|
||||||
const runTui = vi.fn();
|
|
||||||
|
|
||||||
const runtime = {
|
|
||||||
log: vi.fn(),
|
|
||||||
error: vi.fn(),
|
|
||||||
exit: vi.fn(() => {
|
|
||||||
throw new Error("exit");
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
const IOS_NODE = {
|
const IOS_NODE = {
|
||||||
nodeId: "ios-node",
|
nodeId: "ios-node",
|
||||||
@@ -51,38 +35,6 @@ function mockCameraGateway(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
vi.mock("../commands/message.js", () => ({ messageCommand }));
|
|
||||||
vi.mock("../commands/status.js", () => ({ statusCommand }));
|
|
||||||
vi.mock("../commands/configure.js", () => ({
|
|
||||||
CONFIGURE_WIZARD_SECTIONS: [
|
|
||||||
"workspace",
|
|
||||||
"model",
|
|
||||||
"web",
|
|
||||||
"gateway",
|
|
||||||
"daemon",
|
|
||||||
"channels",
|
|
||||||
"skills",
|
|
||||||
"health",
|
|
||||||
],
|
|
||||||
configureCommand,
|
|
||||||
configureCommandWithSections,
|
|
||||||
}));
|
|
||||||
vi.mock("../commands/setup.js", () => ({ setupCommand }));
|
|
||||||
vi.mock("../commands/onboard.js", () => ({ onboardCommand }));
|
|
||||||
vi.mock("../runtime.js", () => ({ defaultRuntime: runtime }));
|
|
||||||
vi.mock("./channel-auth.js", () => ({ runChannelLogin, runChannelLogout }));
|
|
||||||
vi.mock("../tui/tui.js", () => ({ runTui }));
|
|
||||||
vi.mock("../gateway/call.js", () => ({
|
|
||||||
callGateway,
|
|
||||||
randomIdempotencyKey: () => "idem-test",
|
|
||||||
buildGatewayConnectionDetails: () => ({
|
|
||||||
url: "ws://127.0.0.1:1234",
|
|
||||||
urlSource: "test",
|
|
||||||
message: "Gateway target: ws://127.0.0.1:1234",
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
vi.mock("./deps.js", () => ({ createDefaultDeps: () => ({}) }));
|
|
||||||
|
|
||||||
const { buildProgram } = await import("./program.js");
|
const { buildProgram } = await import("./program.js");
|
||||||
|
|
||||||
describe("cli program (nodes media)", () => {
|
describe("cli program (nodes media)", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user