🧪
Testing20M+/wkBSD-3-Clause

istanbul-lib-coverage

Istanbul is the standard JavaScript code coverage tool that instruments your code to track which lines, branches, functions, and statements are executed during

Installation

npm
npm install -D istanbul-lib-coverage
yarn
yarn add -D istanbul-lib-coverage
pnpm
pnpm add -D istanbul-lib-coverage

Import

ESM
import { createCoverageMap } from 'istanbul-lib-coverage';

Quick Example

usage
// Istanbul is typically used through Jest or nyc
// In jest.config.js:
module.exports = {
  collectCoverage: true,
  coverageReporters: ['text', 'html', 'lcov'],
  coverageThreshold: {
    global: { branches: 80, lines: 80 },
  },
};

About istanbul-lib-coverage

Istanbul is the standard JavaScript code coverage tool that instruments your code to track which lines, branches, functions, and statements are executed during testing. The Istanbul project provides the underlying libraries used by both nyc (the CLI) and Jest's built-in coverage reporting. Istanbul instruments JavaScript code by inserting counters that record execution, then generates coverage reports showing which parts of your code were exercised by tests and which were missed. The tool supports multiple report formats including HTML with syntax-highlighted source views, LCOV for CI integration, JSON for programmatic consumption, text for terminal output, and Cobertura for Jenkins integration. Istanbul handles modern JavaScript features including arrow functions, destructuring, optional chaining, and class fields through integration with Babel or V8's native coverage. The libraries in the Istanbul suite include istanbul-lib-instrument for code transformation, istanbul-lib-coverage for coverage map operations, istanbul-lib-report for report generation, and istanbul-reports for built-in reporter implementations. Understanding Istanbul's role is important because it powers the coverage features of Jest, Vitest, and nyc.

Quick Facts

Packageistanbul-lib-coverage
CategoryTesting
Weekly Downloads20M+
LicenseBSD-3-Clause
Installnpm install -D istanbul-lib-coverage

Related Packages

Browse npm Packages by Category

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