mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 15:01:41 +03:00
perf(test): gate monitor runtime logs during vitest
This commit is contained in:
@@ -7,8 +7,22 @@ export type RuntimeEnv = {
|
||||
exit: (code: number) => never;
|
||||
};
|
||||
|
||||
function shouldEmitRuntimeLog(env: NodeJS.ProcessEnv = process.env): boolean {
|
||||
if (env.VITEST !== "true") {
|
||||
return true;
|
||||
}
|
||||
if (env.OPENCLAW_TEST_RUNTIME_LOG === "1") {
|
||||
return true;
|
||||
}
|
||||
const maybeMockedLog = console.log as unknown as { mock?: unknown };
|
||||
return typeof maybeMockedLog.mock === "object";
|
||||
}
|
||||
|
||||
export const defaultRuntime: RuntimeEnv = {
|
||||
log: (...args: Parameters<typeof console.log>) => {
|
||||
if (!shouldEmitRuntimeLog()) {
|
||||
return;
|
||||
}
|
||||
clearActiveProgressLine();
|
||||
console.log(...args);
|
||||
},
|
||||
@@ -22,3 +36,22 @@ export const defaultRuntime: RuntimeEnv = {
|
||||
throw new Error("unreachable"); // satisfies tests when mocked
|
||||
},
|
||||
};
|
||||
|
||||
export function createNonExitingRuntime(): RuntimeEnv {
|
||||
return {
|
||||
log: (...args: Parameters<typeof console.log>) => {
|
||||
if (!shouldEmitRuntimeLog()) {
|
||||
return;
|
||||
}
|
||||
clearActiveProgressLine();
|
||||
console.log(...args);
|
||||
},
|
||||
error: (...args: Parameters<typeof console.error>) => {
|
||||
clearActiveProgressLine();
|
||||
console.error(...args);
|
||||
},
|
||||
exit: (code: number): never => {
|
||||
throw new Error(`exit ${code}`);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user