Add log4js fileSync logger module and formatError helper
This commit is contained in:
22
src/server/log-format.test.ts
Normal file
22
src/server/log-format.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user