mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 02:32:44 +00:00
test(cli): dedupe runtime capture fixtures across command specs
This commit is contained in:
28
src/cli/test-runtime-capture.ts
Normal file
28
src/cli/test-runtime-capture.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
|
||||
export type CliRuntimeCapture = {
|
||||
runtimeLogs: string[];
|
||||
runtimeErrors: string[];
|
||||
defaultRuntime: Pick<RuntimeEnv, "log" | "error" | "exit">;
|
||||
resetRuntimeCapture: () => void;
|
||||
};
|
||||
|
||||
export function createCliRuntimeCapture(): CliRuntimeCapture {
|
||||
const runtimeLogs: string[] = [];
|
||||
const runtimeErrors: string[] = [];
|
||||
return {
|
||||
runtimeLogs,
|
||||
runtimeErrors,
|
||||
defaultRuntime: {
|
||||
log: (msg: string) => runtimeLogs.push(msg),
|
||||
error: (msg: string) => runtimeErrors.push(msg),
|
||||
exit: (code: number) => {
|
||||
throw new Error(`__exit__:${code}`);
|
||||
},
|
||||
},
|
||||
resetRuntimeCapture: () => {
|
||||
runtimeLogs.length = 0;
|
||||
runtimeErrors.length = 0;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user