nyc is Istanbul’s CLI for JavaScript coverage. It instruments code during tests and reports how thoroughly suites exercise your project.
Overview
nyc is the command-line front end to Istanbul’s JavaScript coverage tooling. It inserts line counters into ES5 and ES2015+ source so unit tests reveal which lines, branches, and functions ran. It cooperates with runners such as tap, mocha, and AVA, and handles apps that spawn subprocesses plus source-mapped Babel and TypeScript projects.
Install it as a dev dependency or invoke via npx, then prefix existing test commands with nyc. Configuration lives in package.json, .nycrc files, or nyc.config.js, covering reporters, include and exclude globs, coverage thresholds, caching, and merging results from multiple runs.
Presets exist for Babel and TypeScript setups. Users on jest or tap may rely on those tools’ built-in Istanbul integration instead. Advanced options control all-file instrumentation, subprocess handling, watermarks, and Istanbul ignore hints in source.
The tool is widely used to gate CI on coverage minimums and to produce HTML or lcov reports for review.
Key features
- CLI wrapper over Istanbul instrumentation
- Subprocess coverage collection
- Babel and TypeScript source-map support
- Multiple reporters including lcov and text
- Include and exclude glob selection
- Configurable coverage thresholds
- Merge reports across test runs
- Shared config via extends and npm modules
Use cases
- Measure unit test coverage in Node projects
- Enforce coverage thresholds in CI
- Generate HTML coverage reports
- Combine coverage from parallel test jobs