CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-istanbul-lib-coverage

Data library for istanbul coverage objects providing read-only API with merge and summarize capabilities

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

coverage-maps.mddocs/

Coverage Maps

Coverage maps are collections of file coverage objects keyed by file path, providing operations for merging, filtering, and analyzing coverage data across multiple files.

Capabilities

CoverageMap Constructor

Creates a new coverage map from existing coverage data or another coverage map.

/**
 * Creates a CoverageMap instance
 * @param {Object|CoverageMap} [obj] - Coverage map data or existing CoverageMap
 */
constructor(obj)

Usage Examples:

const { createCoverageMap } = require('istanbul-lib-coverage');

// Create empty coverage map
const map = createCoverageMap();

// Create from global coverage variable
const map = createCoverageMap(global.__coverage__);

// Create from existing coverage map
const map = createCoverageMap(existingMap);

Merge Coverage Maps

Merges another coverage map into the current one, combining coverage data for matching files.

/**
 * Merges another coverage map into this one
 * @param {CoverageMap|Object} obj - Coverage map to merge
 */
merge(obj): void

Usage Examples:

const map1 = createCoverageMap(coverage1);
const map2 = createCoverageMap(coverage2);

// Merge map2 into map1
map1.merge(map2);

// Merge raw coverage data
map1.merge(rawCoverageData);

Filter Coverage Map

Filters the coverage map based on file paths using a callback function.

/**
 * Filters coverage map based on callback
 * @param {Function} callback - Returns true if path should be included
 */
filter(callback): void

Usage Examples:

const map = createCoverageMap(globalCoverage);

// Keep only JavaScript files
map.filter(filePath => filePath.endsWith('.js'));

// Exclude test files
map.filter(filePath => !filePath.includes('test'));

// Keep specific directory
map.filter(filePath => filePath.startsWith('/src/'));

Get File List

Returns an array of file paths for which the map has coverage data.

/**
 * Returns array of file paths with coverage
 * @returns {string[]} Array of file paths
 */
files(): string[]

Usage Examples:

const map = createCoverageMap(globalCoverage);
const files = map.files();

console.log(`Coverage available for ${files.length} files:`);
files.forEach(file => console.log(file));

Get File Coverage

Returns the file coverage object for a specified file path.

/**
 * Returns file coverage for specified file
 * @param {string} file - File path
 * @returns {FileCoverage} File coverage object
 * @throws {Error} If file not found in map
 */
fileCoverageFor(file): FileCoverage

Usage Examples:

const map = createCoverageMap(globalCoverage);

try {
  const fileCoverage = map.fileCoverageFor('/src/index.js');
  console.log('Line coverage:', fileCoverage.getLineCoverage());
} catch (error) {
  console.error('File not found:', error.message);
}

Add File Coverage

Adds a file coverage object to the map, merging with existing coverage if the path already exists.

/**
 * Adds file coverage to map, merging if path exists
 * @param {FileCoverage} fc - File coverage object to add
 */
addFileCoverage(fc): void

Usage Examples:

const { createCoverageMap, createFileCoverage } = require('istanbul-lib-coverage');

const map = createCoverageMap();
const fileCoverage = createFileCoverage('/src/utils.js');

// Add new file coverage
map.addFileCoverage(fileCoverage);

// Adding duplicate path will merge coverage
const anotherFileCoverage = createFileCoverage('/src/utils.js');
map.addFileCoverage(anotherFileCoverage); // Merges with existing

Get Coverage Summary

Returns an aggregated coverage summary for all files in the map.

/**
 * Returns coverage summary for all files in map
 * @returns {CoverageSummary} Aggregated coverage summary
 */
getCoverageSummary(): CoverageSummary

Usage Examples:

const map = createCoverageMap(globalCoverage);
const summary = map.getCoverageSummary();

console.log('Overall coverage:');
console.log(`Lines: ${summary.lines.pct}%`);
console.log(`Statements: ${summary.statements.pct}%`);
console.log(`Functions: ${summary.functions.pct}%`);
console.log(`Branches: ${summary.branches.pct}%`);

JSON Serialization

Returns a JSON-serializable representation of the coverage map.

/**
 * Returns JSON-serializable POJO
 * @returns {Object} Raw coverage map data
 */
toJSON(): Object

Usage Examples:

const map = createCoverageMap(globalCoverage);
const jsonData = map.toJSON();

// Save to file
const fs = require('fs');
fs.writeFileSync('coverage.json', JSON.stringify(jsonData, null, 2));

// Send over network
response.json(jsonData);

docs

coverage-maps.md

coverage-summaries.md

file-coverage.md

index.md

tile.json