nyc
nyc is the command-line interface for Istanbul code coverage, providing an easy way to add coverage instrumentation to any Node.js test runner. By simply prefix…
Installation
npm install -D nyc
yarn add -D nyc
pnpm add -D nyc
Import
// Used as CLI: nyc mocha
Quick Example
// package.json scripts:
// "test": "nyc mocha"
// "coverage": "nyc report --reporter=html"
// .nycrc.json:
{
"all": true,
"include": ["src/**/*.js"],
"reporter": ["text", "html"],
"branches": 80
}About nyc
nyc is the command-line interface for Istanbul code coverage, providing an easy way to add coverage instrumentation to any Node.js test runner. By simply prefixing your test command with nyc (e.g., nyc mocha), it transparently instruments your code at runtime and produces coverage reports after tests complete. nyc supports on-the-fly instrumentation without a separate build step, source map support for transpiled code, per-file coverage enforcement with configurable thresholds, and merging coverage from multiple test runs. Configuration can be specified in .nycrc, .nycrc.json, package.json, or on the command line, controlling which files to include or exclude, report formats, and minimum coverage thresholds that cause the tool to exit with a non-zero status when not met. nyc handles ES modules, TypeScript (through ts-node or babel), and modern JavaScript features through pluggable instrumenters. The tool provides a check-coverage command for CI pipelines that fails builds when coverage drops below thresholds, and a merge command for combining coverage from parallel test runs. nyc is the standard coverage tool for Mocha-based test suites and any test runner that does not include built-in coverage support.
Quick Facts
| Package | nyc |
| Category | Testing |
| Weekly Downloads | 6M+ |
| License | ISC |
| Install | npm install -D nyc |
Related Packages
Istanbul is the standard JavaScript code coverage tool that instruments your code to track which lin…
Mocha is a feature-rich JavaScript test framework that runs on Node.js and in the browser, providing…
Jest is a delightful JavaScript testing framework with a focus on simplicity, created by Facebook. I…
Vitest is a blazing-fast unit testing framework powered by Vite, designed as a modern alternative to…
Chai is a BDD/TDD assertion library for Node.js and the browser that pairs with any JavaScript testi…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.