mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 18:17:27 +00:00
perf(test): fold globals unit tests into logger suite
This commit is contained in:
1
src/canvas-host/a2ui/.bundle.hash
Normal file
1
src/canvas-host/a2ui/.bundle.hash
Normal file
@@ -0,0 +1 @@
|
||||
07a29aa6e54285e1a54e695e91653b2f62f637e62b173813d6d588db2485a37a
|
||||
19896
src/canvas-host/a2ui/a2ui.bundle.js
Normal file
19896
src/canvas-host/a2ui/a2ui.bundle.js
Normal file
File diff suppressed because one or more lines are too long
@@ -1,29 +0,0 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { isVerbose, isYes, logVerbose, setVerbose, setYes } from "./globals.js";
|
||||
|
||||
describe("globals", () => {
|
||||
afterEach(() => {
|
||||
setVerbose(false);
|
||||
setYes(false);
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("toggles verbose flag and logs when enabled", () => {
|
||||
const logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
setVerbose(false);
|
||||
logVerbose("hidden");
|
||||
expect(logSpy).not.toHaveBeenCalled();
|
||||
|
||||
setVerbose(true);
|
||||
logVerbose("shown");
|
||||
expect(isVerbose()).toBe(true);
|
||||
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("shown"));
|
||||
});
|
||||
|
||||
it("stores yes flag", () => {
|
||||
setYes(true);
|
||||
expect(isYes()).toBe(true);
|
||||
setYes(false);
|
||||
expect(isYes()).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { RuntimeEnv } from "./runtime.js";
|
||||
import { setVerbose } from "./globals.js";
|
||||
import { isVerbose, isYes, logVerbose, setVerbose, setYes } from "./globals.js";
|
||||
import { logDebug, logError, logInfo, logSuccess, logWarn } from "./logger.js";
|
||||
import { DEFAULT_LOG_DIR, resetLogger, setLoggerOverride } from "./logging.js";
|
||||
|
||||
@@ -13,6 +13,7 @@ describe("logger helpers", () => {
|
||||
resetLogger();
|
||||
setLoggerOverride(null);
|
||||
setVerbose(false);
|
||||
setYes(false);
|
||||
});
|
||||
|
||||
it("formats messages through runtime log/error", () => {
|
||||
@@ -88,6 +89,33 @@ describe("logger helpers", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("globals", () => {
|
||||
afterEach(() => {
|
||||
setVerbose(false);
|
||||
setYes(false);
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("toggles verbose flag and logs when enabled", () => {
|
||||
const logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
setVerbose(false);
|
||||
logVerbose("hidden");
|
||||
expect(logSpy).not.toHaveBeenCalled();
|
||||
|
||||
setVerbose(true);
|
||||
logVerbose("shown");
|
||||
expect(isVerbose()).toBe(true);
|
||||
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("shown"));
|
||||
});
|
||||
|
||||
it("stores yes flag", () => {
|
||||
setYes(true);
|
||||
expect(isYes()).toBe(true);
|
||||
setYes(false);
|
||||
expect(isYes()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
function pathForTest() {
|
||||
const file = path.join(os.tmpdir(), `openclaw-log-${crypto.randomUUID()}.log`);
|
||||
fs.mkdirSync(path.dirname(file), { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user