forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissue-231-console-logger.test.ts
More file actions
78 lines (66 loc) · 2.59 KB
/
Copy pathissue-231-console-logger.test.ts
File metadata and controls
78 lines (66 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { ConsoleRuntimeLogger } from "../../src/logger/runtime-logger.js";
describe("ConsoleRuntimeLogger warn dedup + level filtering (Issue #231)", () => {
let debugSpy: ReturnType<typeof vi.spyOn>;
let infoSpy: ReturnType<typeof vi.spyOn>;
let warnSpy: ReturnType<typeof vi.spyOn>;
let errorSpy: ReturnType<typeof vi.spyOn>;
beforeEach(() => {
debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
});
afterEach(() => {
debugSpy.mockRestore();
infoSpy.mockRestore();
warnSpy.mockRestore();
errorSpy.mockRestore();
});
it("exposes a single warn method on the prototype", () => {
const descriptor = Object.getOwnPropertyDescriptor(
ConsoleRuntimeLogger.prototype,
"warn"
);
expect(descriptor).toBeDefined();
expect(typeof descriptor?.value).toBe("function");
});
it("with level error, warn makes no console.warn call", () => {
const logger = new ConsoleRuntimeLogger({ level: "error" });
expect(logger.level).toBe("error");
logger.debug("d");
logger.info("i");
logger.warn("w");
logger.error("e");
expect(debugSpy).not.toHaveBeenCalled();
expect(infoSpy).not.toHaveBeenCalled();
expect(warnSpy).not.toHaveBeenCalled();
expect(errorSpy).toHaveBeenCalledTimes(1);
expect(errorSpy).toHaveBeenCalledWith("e", {});
});
it("with level warn, info is suppressed while warn and error print", () => {
const logger = new ConsoleRuntimeLogger({ level: "warn" });
expect(logger.level).toBe("warn");
logger.debug("d");
logger.info("i");
logger.warn("w");
logger.error("e");
expect(debugSpy).not.toHaveBeenCalled();
expect(infoSpy).not.toHaveBeenCalled();
expect(warnSpy).toHaveBeenCalledTimes(1);
expect(warnSpy).toHaveBeenCalledWith("w", {});
expect(errorSpy).toHaveBeenCalledTimes(1);
expect(errorSpy).toHaveBeenCalledWith("e", {});
});
it("routes every level through the same shouldLog gate", () => {
const logger = new ConsoleRuntimeLogger({ level: "info" });
logger.debug("hidden");
logger.info("shown-info");
logger.warn("shown-warn");
logger.error("shown-error");
expect(debugSpy).not.toHaveBeenCalled();
expect(infoSpy).toHaveBeenCalledTimes(1);
expect(warnSpy).toHaveBeenCalledTimes(1);
expect(errorSpy).toHaveBeenCalledTimes(1);
});
});