Skip to content

chore(test): setup test coverage with c8 - #263

Merged
LeoMcA merged 6 commits into
mainfrom
test-coverage
Mar 20, 2026
Merged

chore(test): setup test coverage with c8#263
LeoMcA merged 6 commits into
mainfrom
test-coverage

Conversation

@caugner

@caugner caugner commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Description

Sets up test coverage with c8, and adds a test:coverage script.

Motivation

Make it easy to identify missing test coverage.

Additional details

See this test job run to see how it looks.

Reasons for using c8 instead of experimental Node-native coverage reporters:

  • c8 allows defining file excludes
  • c8 allows excluding parts of files (see this GitHub search in BCD)
  • c8 creates multiple reports simultaneously (1. text summary, 2. lcov.info, 3. index.html with visual), whereas you'd need to run node --test twice to get both
  • c8 includes files without any coverage, whereas node --experimental-test-coverage omits these (see Report 0% coverage for untested files in a project (i.e., files matching some glob) nodejs/node#58887)
  • performance is comparable:
    node --test --experimental-test-coverage  0.92s user 0.18s system 100% cpu 1.091 total
    node --test --experimental-test-coverage --test-reporter=lcov   0.93s user 0.11s system 148% cpu 0.702 total
    npx c8 node --test  0.98s user 0.21s system 112% cpu 1.053 total
    

Related issues and pull requests

@caugner
caugner requested review from a team and mdn-bot as code owners March 17, 2026 16:37
@caugner
caugner requested a review from LeoMcA March 17, 2026 16:37
@caugner
caugner marked this pull request as ready for review March 17, 2026 17:01

@LeoMcA LeoMcA left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

c8 allows excluding parts of files (see this GitHub search in BCD)

FWIW the node test runner supports this too: https://github.com/mdn/mcp/blob/c7847b7ccadcdb0b47bbd8dd76269fa0ae59a459/sentry/init.js#L5

But the other arguments are compelling. Looks good!

@LeoMcA
LeoMcA merged commit 51561c5 into main Mar 20, 2026
6 checks passed
@LeoMcA
LeoMcA deleted the test-coverage branch March 20, 2026 12:26
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.

3 participants