test(cli): dedupe runtime capture fixtures across command specs

This commit is contained in:
Peter Steinberger
2026-02-18 13:27:07 +00:00
parent 3af9f704c8
commit 8f866d51c4
7 changed files with 59 additions and 90 deletions

View 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;
},
};
}