test: add debug logger unit coverage - #1069
Conversation
sonukapoor
left a comment
There was a problem hiding this comment.
Nice work, William - the tests trace through every real branch in createDebugLogger and formatJson, the ESM mock setup with unstable_mockModule + beforeAll dynamic import is correct, and the fixed clock keeps it deterministic. One optional gap: null as details isn't covered - it bypasses the === undefined check and hits JSON.stringify(null) which returns "null" (the string-conversion fallback never fires). Not a blocker, but if you want to squeeze out the last branch:
it("serializes null details as JSON null", () => {
const debug = createDebugLogger(true);
debug.log("request", null);
expect(appendFileSyncMock).toHaveBeenCalledWith(
expect.any(String),
"2026-08-23T06:00:00.000Z [debug] request null\n",
"utf8",
);
});Happy to merge as-is if you'd rather leave it.
|
Merged - thank you @WilliamK112! |
|
One small ask - if you haven't already, a star on the repo goes a long way for an open source project like this: https://github.com/OWASP/cve-lite-cli. Thanks again! |
What changed and why
Adds dedicated unit coverage for
createDebugLogger, including:announcePathbehaviorThe tests mock
node:fsand use a fixed clock, so they never create real log files. The focused suite reaches 100% statement, branch, function, and line coverage forsrc/output/debug.ts.Closes #1029
Validation
npm cinpm run lint:testsnpm run buildnode dist/index.js advisories sync— 227,853 records syncednpm test -- --runInBand— 132 suites, 1,648 tests passed