mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:00:42 +00:00
test: reuse CLI runtime mock in gateway tests
This commit is contained in:
@@ -33,28 +33,9 @@ const gatewayStatusCommand = vi.fn<(opts: unknown) => Promise<void>>(async () =>
|
||||
const inspectPortUsage = vi.fn(async (_port: number) => ({ status: "free" as const }));
|
||||
const formatPortDiagnostics = vi.fn((_diagnostics: unknown) => [] as string[]);
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
const runtimeLogs: string[] = [];
|
||||
const runtimeErrors: string[] = [];
|
||||
const stringifyArgs = (args: unknown[]) => args.map((value) => String(value)).join(" ");
|
||||
const defaultRuntime = {
|
||||
log: vi.fn((...args: unknown[]) => {
|
||||
runtimeLogs.push(stringifyArgs(args));
|
||||
}),
|
||||
error: vi.fn((...args: unknown[]) => {
|
||||
runtimeErrors.push(stringifyArgs(args));
|
||||
}),
|
||||
writeStdout: vi.fn((value: string) => {
|
||||
defaultRuntime.log(value.endsWith("\n") ? value.slice(0, -1) : value);
|
||||
}),
|
||||
writeJson: vi.fn((value: unknown, space = 2) => {
|
||||
defaultRuntime.log(JSON.stringify(value, null, space > 0 ? space : undefined));
|
||||
}),
|
||||
exit: vi.fn((code: number) => {
|
||||
throw new Error(`__exit__:${code}`);
|
||||
}),
|
||||
};
|
||||
return { runtimeLogs, runtimeErrors, defaultRuntime };
|
||||
const mocks = await vi.hoisted(async () => {
|
||||
const { createCliRuntimeMock } = await import("./test-runtime-mock.js");
|
||||
return createCliRuntimeMock(vi);
|
||||
});
|
||||
|
||||
const { runtimeLogs, runtimeErrors, defaultRuntime } = mocks;
|
||||
|
||||
@@ -46,28 +46,9 @@ const callGateway = vi.fn(async (opts: NodeInvokeCall) => {
|
||||
|
||||
const randomIdempotencyKey = vi.fn(() => "rk_test");
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
const runtimeErrors: string[] = [];
|
||||
const stringifyArgs = (args: unknown[]) => args.map((value) => String(value)).join(" ");
|
||||
const defaultRuntime = {
|
||||
log: vi.fn(),
|
||||
error: vi.fn((...args: unknown[]) => {
|
||||
runtimeErrors.push(stringifyArgs(args));
|
||||
}),
|
||||
writeStdout: vi.fn((value: string) => {
|
||||
defaultRuntime.log(value.endsWith("\n") ? value.slice(0, -1) : value);
|
||||
}),
|
||||
writeJson: vi.fn((value: unknown, space = 2) => {
|
||||
defaultRuntime.log(JSON.stringify(value, null, space > 0 ? space : undefined));
|
||||
}),
|
||||
exit: vi.fn((code: number) => {
|
||||
throw new Error(`__exit__:${code}`);
|
||||
}),
|
||||
};
|
||||
return {
|
||||
runtimeErrors,
|
||||
defaultRuntime,
|
||||
};
|
||||
const mocks = await vi.hoisted(async () => {
|
||||
const { createCliRuntimeMock } = await import("./test-runtime-mock.js");
|
||||
return createCliRuntimeMock(vi);
|
||||
});
|
||||
|
||||
const { runtimeErrors, defaultRuntime } = mocks;
|
||||
|
||||
Reference in New Issue
Block a user