import { dlog } from "../src/dlog"; describe("dlog utility", () => { beforeAll(() => { dlog.setConfig({ isDev: true }); }); it("should log debug, info, success, and error messages", () => { dlog.d("Debug message", { foo: "bar" }); dlog.i("Info message", [1, 2, 3]); dlog.s("Success message", "All good!"); dlog.e("Error message", { error: true }); }); it("should redact sensitive fields in objects", () => { const obj = { apiKey: "12345", token: "secret", normal: "value" }; dlog.d("Redacted object", obj); }); it("should log exceptions with stack trace", () => { try { throw new Error("Test exception"); } catch (err) { dlog.ex(err as Error, false, "Exception occurred"); } }); it("should return and clear the log history", () => { dlog.d("Test debug log"); dlog.i("Test info log"); const history = dlog.getLogHistoryAndFlash(); expect(Array.isArray(history)).toBe(true); expect(history.length).toBeGreaterThanOrEqual(2); expect(history.some((line) => line.includes("Test debug log"))).toBe(true); expect(history.some((line) => line.includes("Test info log"))).toBe(true); // After flash, history should be empty const afterFlash = dlog.getLogHistoryAndFlash(); expect(afterFlash.length).toBe(0); }); });