Skip to content

build(tests): setup test coverage with c8 - #1908

Open
caugner wants to merge 1 commit into
mainfrom
setup-c8-coverage
Open

caugner wants to merge 1 commit into
mainfrom
setup-c8-coverage

Conversation

@caugner

@caugner caugner commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Description

Sets up test coverage with c8, adds a --coverage option to npm test -- unit, and uses it in CI.

Motivation

Make it easier to identify missing test coverage.

Additional details

Unlike mdn/dex#263, coverage is enabled via npm test -- unit --coverage rather than a separate test:coverage script, because fred routes all test commands through scripts/tests.js.

The .c8rc.json excludes types/, legacy/, vendor/, scripts/, test/, build output and config files, and limits reporting to .js files. The generated coverage/ directory is ignored in git, Prettier, and tsconfig.json; ESLint and stylelint already pick up .gitignore.

Related issues and pull requests

Same as mdn/dex#263 and mdn/private-locale-translator#279.

@github-actions

Copy link
Copy Markdown
Contributor

f1e6af2 was deployed to: https://fred-pr1908.review.mdn.allizom.net/

Add a `--coverage` option to the `unit` test command that wraps
`node --test` with `c8`, and use it in CI.

`all: true` reports files without any coverage. Type declarations,
generated output, the legacy bundle, vendored code, scripts, and tests
themselves are excluded.
@caugner caugner changed the title chore(test): setup test coverage with c8 test: measure test coverage with c8 Sep 14, 2026
@caugner caugner changed the title test: measure test coverage with c8 build(test): measure test coverage with c8 Sep 14, 2026
@caugner caugner changed the title build(test): measure test coverage with c8 build(tests): setup test coverage with c8 Sep 14, 2026
@caugner
caugner marked this pull request as ready for review September 14, 2026 15:08
@caugner
caugner requested review from a team and mdn-bot as code owners September 14, 2026 15:08
@caugner
caugner requested a review from LeoMcA September 14, 2026 15:08
Comment thread .c8rc.json
"dist/**",
"legacy/**",
"out/**",
"scripts/**",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With "all": true, every non-excluded .js file is reported, so build-time tooling that unit tests never load is counted as 0% and dilutes the metric. scripts/** and test/** are excluded, but two equivalent categories are not:

  • build/** — 15 build-time files (build/loaders/*.js, build/plugins/*.js, build/eslint-fred.js, build/hmr.js, …), the same kind of tooling as scripts/**.
  • wdio.conf.js — e2e runner config; it does not match *.config.js, so it slips through while test/** is excluded.

Add both:

Suggested change
"scripts/**",
"scripts/**",
"build/**",
"wdio.conf.js",

AI-generated review by Claude

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