Coverage processing utilities provide functions for filtering, transforming, and preparing coverage data for reporting and aggregation. These utilities handle file path resolution, data merging, and configuration management for the coverage pipeline.
Functions for filtering and cleaning coverage data to remove test files and irrelevant entries.
/**
* Removes spec files and support files from coverage data
* @param totalCoverage - Coverage object to filter
* @param config - Cypress configuration object (optional)
* @param env - Cypress environment object (optional)
* @param spec - Current spec information (optional)
* @returns Filtered coverage object with only application files
*/
function filterFilesFromCoverage(
totalCoverage: Coverage,
config?: Cypress.Config,
env?: Cypress.Environment,
spec?: Cypress.Spec
): Coverage;Usage:
// Automatic filtering in coverage hooks
const cleanCoverage = filterFilesFromCoverage(window.__coverage__)
// The main filtering function handles all filtering logic internallyFiltering behavior:
specPattern or testFiles configurationcodeCoverage.exclude environment variableUtilities for reading, combining, and managing NYC configuration from multiple sources.
/**
* Reads NYC configuration from all possible sources
* @param workingDirectory - Directory to search for config files
* @returns Combined NYC options object
*/
function readNycOptions(workingDirectory: string): NycOptions;
/**
* Combines multiple NYC configuration objects with precedence
* @param options - NYC configuration objects to merge
* @returns Merged configuration object
*/
function combineNycOptions(...options: NycOptions[]): NycOptions;Configuration sources (in order of precedence):
.nycrc (JSON).nycrc.json.nycrc.yaml.nycrc.ymlnyc.config.jsnyc.config.cjspackage.json nyc fieldUsage:
// Read all NYC configuration
const nycOptions = readNycOptions(process.cwd())
// Combine custom options
const finalOptions = combineNycOptions(
defaultNycOptions,
projectOptions,
customOptions
)Functions for resolving and correcting file paths in coverage data.
/**
* Converts relative paths to absolute paths in coverage data
* @param nycFilename - Path to NYC coverage file
*/
function resolveRelativePaths(nycFilename: string): void;
/**
* Fixes source file paths in coverage objects
* @param coverage - Coverage object to modify in-place
*/
function fixSourcePaths(coverage: Coverage): void;
/**
* Attempts to locate missing source files using glob patterns
* @param nycFilename - Path to NYC coverage file
*/
function tryFindingLocalFiles(nycFilename: string): void;Path resolution behavior:
Utilities for working with coverage data structure and placeholders.
/**
* Creates placeholder coverage entry for uncovered files
* @param fullPath - Full path to the file
* @returns Placeholder coverage object
*/
function fileCoveragePlaceholder(fullPath: string): FileCoverage;
/**
* Removes placeholder entries from coverage object
* @param coverage - Coverage object to clean (modified in-place)
*/
function removePlaceholders(coverage: Coverage): void;
/**
* Includes all files in coverage report, even uncovered ones
* @param nycFilename - Path to NYC coverage file
* @param nycReportOptions - NYC configuration options
*/
function includeAllFiles(
nycFilename: string,
nycReportOptions: NycOptions
): void;Placeholder structure:
{
path: '/full/path/to/file.js',
statementMap: {},
fnMap: {},
branchMap: {},
s: {},
f: {},
b: {}
// Note: No 'hash' property indicates placeholder
}Functions for creating and applying file exclusion patterns.
/**
* Gets batch size for coverage transmission
* @returns Parsed batch size or null if invalid
*/
function getSendCoverageBatchSize(): number | null;Pattern sources:
specPattern configurationtestFiles configuration (legacy)integrationFolder patterns (legacy)codeCoverage.exclude environment variableFunctions for displaying coverage information and validation results.
/**
* Displays NYC configuration and coverage file information
* @param nycFilename - Path to NYC coverage file
*/
function showNycInfo(nycFilename: string): void;
/**
* Validates that all coverage file paths exist
* @param nycFilename - Path to NYC coverage file
* @returns true if all paths are missing, false otherwise
*/
function checkAllPathsNotFound(nycFilename: string): boolean;Information displayed:
The processing utilities provide sensible defaults for NYC configuration:
const defaultNycOptions: NycOptions = {
'report-dir': './coverage',
'temp-dir': './.nyc_output',
reporter: ['lcov', 'clover', 'json', 'json-summary'],
extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx'],
excludeAfterRemap: false
};// Create custom filter for specific patterns
const customFilter = (totalCoverage) => {
return Object.keys(totalCoverage).reduce((filtered, filepath) => {
// Keep only application source files
if (filepath.includes('/src/') && !filepath.includes('.test.')) {
filtered[filepath] = totalCoverage[filepath]
}
return filtered
}, {})
}// Configure coverage transmission batching
Cypress.env('sendCoverageBatchSize', 25)
// Or programmatically:
const batchSize = getSendCoverageBatchSize()
if (batchSize && Object.keys(coverage).length > batchSize) {
sendBatchCoverage(coverage, batchSize)
} else {
sendCoverage(coverage)
}// Environment-specific NYC configuration
const baseOptions = readNycOptions(process.cwd())
const envOptions = process.env.NODE_ENV === 'production'
? { reporter: ['json-summary'] }
: { reporter: ['lcov', 'text'] }
const finalOptions = combineNycOptions(baseOptions, envOptions)