import { describe, it, expect } from "vitest"; import { formatError } from "./log-format"; describe("formatError", () => { it("returns stack for Error", () => { const e = new Error("boom"); expect(formatError(e)).toBe(e.stack); }); it("falls back to message when stack missing", () => { const e = new Error("boom"); e.stack = undefined as unknown as string; expect(formatError(e)).toBe("boom"); }); it("stringifies non-Error primitives", () => { expect(formatError("oops")).toBe("oops"); expect(formatError(42)).toBe("42"); }); it("handles null / undefined", () => { expect(formatError(null)).toBe("Unknown error"); expect(formatError(undefined)).toBe("Unknown error"); }); });