# How to generate a coverage report for a node:test suite

> Enable coverage in Node.js’s built-in test runner, print a terminal summary, and save an LCOV file for CI while keeping test results visible.

Canonical URL: https://www.devobs.io/articles/how-do-i-generate-a-coverage-report-for-a-node-test-suite/
By: Lucas Vale
Published: 2026-10-23T17:27:24.368Z
Updated: 2026-10-23T17:27:24.368Z
Section: Architecture

Run your `node:test` suite with coverage enabled:

```sh
node --test --experimental-test-coverage
```

Node.js collects code coverage and reports statistics after all tests finish. Coverage collection is documented as experimental, so check the documentation for the Node.js version pinned in your project and CI. [Node.js coverage documentation](https://nodejs.org/api/test.html#collecting-code-coverage)

## Print a coverage summary in the terminal

To explicitly request test output and a coverage summary, select the `spec` reporter:

```sh
node --test --experimental-test-coverage --test-reporter=spec
```

Both `spec` and `tap` print coverage statistics. The coverage flag enables collection; the reporter determines how the results are presented. [Coverage reporters](https://nodejs.org/api/test.html#coverage-reporters)

If no tests run, Node.js does not generate a coverage report. When a summary is missing, check that the command actually ran your tests before investigating the reporter configuration. [Coverage flag reference](https://nodejs.org/api/cli.html#--experimental-test-coverage)

## Save an LCOV file while keeping test results visible

Use two reporters: `spec` for the console and `lcov` for a file:

```sh
node --test --experimental-test-coverage --test-reporter=spec --test-reporter=lcov --test-reporter-destination=stdout --test-reporter-destination=lcov.info
```

This combines Node’s documented LCOV reporter with its multiple-reporter configuration. Reporters and destinations are paired in the order supplied:

- `spec` → `stdout`, keeping test results and the coverage summary in the console.
- `lcov` → `lcov.info`, saving coverage to a file.

When you specify multiple reporters, each must have an explicit destination. A destination can be `stdout`, `stderr`, or a file path. [Multiple reporters](https://nodejs.org/api/test.html#multiple-reporters)

**The LCOV reporter does not report test results.** Pairing it with `spec` provides both test-result output and the coverage file. [Coverage reporters](https://nodejs.org/api/test.html#coverage-reporters)

For CI, use the combined command as your coverage step, then configure your pipeline to retain `lcov.info` as an artifact. If your coverage service accepts LCOV, point it at that file. Keep the console output as well: the test results and coverage artifact serve different purposes.

## Check the report’s scope before interpreting it

A coverage summary needs context: which files were included, and which were deliberately omitted? Node’s documented defaults exclude:

- Node.js core modules.
- Files inside `node_modules/` directories.
- Matching test files.

The documentation identifies `--test-coverage-include` as a way to explicitly include normally excluded core or dependency files, and `--test-coverage-exclude` as a way to override the default test-file exclusions. Check those settings when a report’s scope differs from what you expected. [Coverage collection and exclusions](https://nodejs.org/api/test.html#collecting-code-coverage)

Source-level exclusions matter too. Node supports `/* node:coverage disable */` and `/* node:coverage enable */` to exclude a region. Use `/* node:coverage ignore next */` to ignore the next line, or supply a count—for example, `/* node:coverage ignore next 3 */`—to ignore that many lines. Treat these as deliberate measurement exclusions, not substitutes for tests. [Coverage comments](https://nodejs.org/api/test.html#collecting-code-coverage)

## Keep LCOV and V8 coverage files separate

When `NODE_V8_COVERAGE` specifies a directory, Node writes generated V8 coverage files there. To request an LCOV file, use the `lcov` reporter and its destination instead. The environment variable is not a replacement for the LCOV configuration above. [Coverage collection](https://nodejs.org/api/test.html#collecting-code-coverage) · [LCOV reporter](https://nodejs.org/api/test.html#coverage-reporters)

## Check compatibility with your Node.js version

These examples follow the Node.js v26.12.1 documentation. The CLI history records support for combining `--experimental-test-coverage` with `--test` in Node.js v20.1.0 and v18.17.0. That history concerns the collection flag; it does not establish a minimum version for the complete multi-reporter command or the filtering options. Check each option against the documentation for your pinned runtime. [Flag version history](https://nodejs.org/api/cli.html#--experimental-test-coverage) · [Test runner documentation](https://nodejs.org/api/test.html#collecting-code-coverage)

## Source references

- <https://nodejs.org/api/test.html#collecting-code-coverage>
- <https://nodejs.org/api/test.html#coverage-reporters>
- <https://nodejs.org/api/test.html#multiple-reporters>
- <https://nodejs.org/api/cli.html#--experimental-test-coverage>
