🧪
Testing6M+/wkISC

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
npm install -D nyc
yarn
yarn add -D nyc
pnpm
pnpm add -D nyc

Import

ESM
// Used as CLI: nyc mocha

Quick Example

usage
// 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

Packagenyc
CategoryTesting
Weekly Downloads6M+
LicenseISC
Installnpm install -D nyc

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.