or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

coverage-collection.mdcoverage-processing.mdindex.mdplugin-registration.mdserver-middleware.md
tile.json

coverage-processing.mddocs/

Coverage Processing

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.

Capabilities

Coverage Data Filtering

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 internally

Filtering behavior:

  • Spec files: Removed based on specPattern or testFiles configuration
  • Support files: Removed based on support file directory patterns
  • Custom exclusions: Applied from codeCoverage.exclude environment variable
  • Integration folder: Legacy Cypress integration folder patterns

Configuration Management

Utilities 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):

  1. .nycrc (JSON)
  2. .nycrc.json
  3. .nycrc.yaml
  4. .nycrc.yml
  5. nyc.config.js
  6. nyc.config.cjs
  7. package.json nyc field

Usage:

// Read all NYC configuration
const nycOptions = readNycOptions(process.cwd())

// Combine custom options
const finalOptions = combineNycOptions(
  defaultNycOptions,
  projectOptions,
  customOptions
)

Path Resolution

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:

  • Converts relative paths to absolute paths
  • Handles different working directory contexts
  • Attempts to locate moved or renamed source files
  • Updates coverage data in-place for efficiency

Coverage Data Utilities

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
}

File Pattern Matching

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 configuration
  • testFiles configuration (legacy)
  • integrationFolder patterns (legacy)
  • codeCoverage.exclude environment variable

Information Display

Functions 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:

  • NYC configuration summary
  • Coverage file statistics
  • File path validation results
  • Statement coverage per file

Default Configuration

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
};

Advanced Processing Examples

Custom File Filtering

// 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
  }, {})
}

Batch Processing Configuration

// 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)
}

Multi-Environment Configuration

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