Skip to content

test(bufflog): add a jest suite and a CI workflow - #44

Merged
minac merged 2 commits into
mainfrom
miguel/js-bufflog-tests-ci
Sep 11, 2026
Merged

minac merged 2 commits into
mainfrom
miguel/js-bufflog-tests-ci

Conversation

@minac

@minac minac commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

What

Jest plus ts-jest, 15 tests over two files, and a CI workflow that runs npm ci, npm run build and npm test on node 18 and 20. The tests mock the pino module so bufflog's logger writes to a Writable instead of stdout. That keeps the real level and redact config in play. The middleware tests run a real express server on an ephemeral port.

Why

The package had no tests and no CI (the test script just exited 1). Every service imports it, and the redaction config is the part nobody wants to break quietly.

How

tsconfig.json has no exclude, so tsc now emits dist/__tests__. I kept it out of the tarball with "!dist/__tests__" in files instead of excluding the directory, because npm run build is the regression gate and the tests should go through it.

The redaction assertions deserve the closest look, since they encode what counts as a leak. No library code changed.

How to verify

  1. npm ci
  2. npm run build
  3. npm test (2 suites, 15 tests)

How does it look

N/A, non-visual.

🤖 Generated with Claude Code

This package is published to npm and four services import it, and it had no
tests and no CI. A broken redact path or a changed level number reaches those
services at install time, with nothing in between.

The tests mock the pino module so the module-level logger writes to a Writable
sink instead of stdout. That keeps the real level config and the real redaction
paths in play, and needs no change to bufflog.ts.

Coverage is what bufflog.ts promises: the six custom levels and their numeric
values, the pino redact paths from constants.ts, and the express middleware over
a real HTTP request. One test records that a bare password key in context is not
redacted today, because sanitizeContext() returns the context untouched.

CI runs build (tsc) and test on node 18 and 20. tsc compiles the tests too, so
`files` excludes dist/__tests__ to keep the published tarball at source files
only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@minac
minac requested a review from a team as a code owner September 11, 2026 09:16
@minac minac self-assigned this Sep 11, 2026
@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 67cd46f8-5955-4885-8178-474dc4627ded


Comment @coderabbitai help to get the list of available commands.

@minac
minac requested review from brunojppb and philippemiguet and removed request for brunojppb September 11, 2026 09:22
The test asserted that a bare `context.password` reaches the logs in clear
text. It recorded the leak rather than a behaviour we want, so it reads as
a test for something broken.

Its second assertion, that `context.req.headers` is censored, already runs
in the test above, which loops every key in `serverKeys` including
`headers`. Nothing else is lost.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@minac
minac merged commit 81cfa4d into main Sep 11, 2026
3 checks passed
@minac
minac deleted the miguel/js-bufflog-tests-ci branch September 11, 2026 09:33
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.

2 participants