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 install -D istanbul-lib-coverage
yarn add -D istanbul-lib-coverage
pnpm add -D istanbul-lib-coverage
Import
import { createCoverageMap } from 'istanbul-lib-coverage';Quick Example
// 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
| Package | istanbul-lib-coverage |
| Category | Testing |
| Weekly Downloads | 20M+ |
| License | BSD-3-Clause |
| Install | npm install -D istanbul-lib-coverage |
Related Packages
nyc is the command-line interface for Istanbul code coverage, providing an easy way to add coverage …
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…
Mocha is a feature-rich JavaScript test framework that runs on Node.js and in the browser, providing…
Babel is the standard JavaScript compiler that transforms modern JavaScript and TypeScript syntax in…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.