import { describe, it, expect, beforeEach } from "bun:test"; import { logger, getRecentLogs } from "./logger"; describe("Logger Buffer", () => { // Note: Since the buffer is a module-level variable, it persists across tests. // In a real scenario we might want a reset function, but for now we'll just check relative additions. it("should add logs to the buffer", () => { const initialLength = getRecentLogs().length; logger.info("Test Info Log"); const newLogs = getRecentLogs(); expect(newLogs.length).toBe(initialLength + 1); expect(newLogs[0]?.message).toBe("Test Info Log"); expect(newLogs[0]?.type).toBe("info"); }); it("should cap the buffer size at 50", () => { // Fill the buffer for (let i = 0; i < 60; i++) { logger.debug(`Log overflow test ${i}`); } const logs = getRecentLogs(); expect(logs.length).toBeLessThanOrEqual(50); expect(logs[0]?.message).toBe("Log overflow test 59"); }); it("should handle different log levels", () => { logger.error("Critical Error"); logger.success("Operation Successful"); const logs = getRecentLogs(); expect(logs[0]?.type).toBe("success"); expect(logs[1]?.type).toBe("error"); }); });