forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-logger.test.ts
More file actions
52 lines (42 loc) · 1.66 KB
/
Copy pathruntime-logger.test.ts
File metadata and controls
52 lines (42 loc) · 1.66 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
import { afterEach, describe, expect, it, vi } from "vitest";
import { ConsoleRuntimeLogger } from "../src/index.js";
describe("ConsoleRuntimeLogger", () => {
afterEach(() => {
vi.restoreAllMocks();
});
it("logs info and error messages by default", () => {
const info = vi.spyOn(console, "info").mockImplementation(() => undefined);
const error = vi
.spyOn(console, "error")
.mockImplementation(() => undefined);
const logger = new ConsoleRuntimeLogger();
logger.info("runtime started");
logger.error("runtime failed", { taskId: "task-1" });
expect(info).toHaveBeenCalledWith("runtime started", {});
expect(error).toHaveBeenCalledWith("runtime failed", {
taskId: "task-1"
});
});
it("suppresses info below a warn threshold", () => {
const info = vi.spyOn(console, "info").mockImplementation(() => undefined);
const error = vi
.spyOn(console, "error")
.mockImplementation(() => undefined);
const logger = new ConsoleRuntimeLogger({ level: "warn" });
logger.info("verbose message");
logger.error("important message");
expect(info).not.toHaveBeenCalled();
expect(error).toHaveBeenCalledWith("important message", {});
});
it("allows only errors at the error threshold", () => {
const info = vi.spyOn(console, "info").mockImplementation(() => undefined);
const error = vi
.spyOn(console, "error")
.mockImplementation(() => undefined);
const logger = new ConsoleRuntimeLogger({ level: "error" });
logger.info("verbose message");
logger.error("error message");
expect(info).not.toHaveBeenCalled();
expect(error).toHaveBeenCalledOnce();
});
});