Skip to content

test: add debug logger unit coverage - #1069

Merged
sonukapoor merged 1 commit into
OWASP:mainfrom
WilliamK112:test/debug-logger-1029
Sep 2, 2026
Merged

test: add debug logger unit coverage#1069
sonukapoor merged 1 commit into
OWASP:mainfrom
WilliamK112:test/debug-logger-1029

Conversation

@WilliamK112

Copy link
Copy Markdown
Contributor

What changed and why

Adds dedicated unit coverage for createDebugLogger, including:

  • disabled-session no-op behavior without filesystem writes or stderr output
  • timestamped log filename and formatted line output
  • one-time announcePath behavior
  • plain-string, object, and circular-value detail formatting
  • the enabled session close no-op

The tests mock node:fs and use a fixed clock, so they never create real log files. The focused suite reaches 100% statement, branch, function, and line coverage for src/output/debug.ts.

Closes #1029

Validation

  • npm ci
  • npm run lint:tests
  • npm run build
  • node dist/index.js advisories sync — 227,853 records synced
  • npm test -- --runInBand — 132 suites, 1,648 tests passed
  • focused coverage — 100% statements, branches, functions, and lines

@sonukapoor sonukapoor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sonukapoor
sonukapoor merged commit ad9c756 into OWASP:main Sep 2, 2026
6 checks passed
@sonukapoor

Copy link
Copy Markdown
Collaborator

Merged - thank you @WilliamK112!

@sonukapoor

Copy link
Copy Markdown
Collaborator

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add unit coverage for src/output/debug.ts

2 participants