Run your node:test suite with coverage enabled:
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
Print a coverage summary in the terminal
To explicitly request test output and a coverage summary, select the spec reporter:
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
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
Save an LCOV file while keeping test results visible
Use two reporters: spec for the console and lcov for a file:
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
The LCOV reporter does not report test results. Pairing it with spec provides both test-result output and the coverage file. 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
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
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 · LCOV reporter
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 · Test runner documentation
Sources are linked throughout this guide. Product capabilities can change; consult the linked documentation for your deployment.
Read our editorial approach ↗