CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-istanbul-lib-source-maps

Source maps support for Istanbul code coverage toolkit, enabling accurate coverage reporting for transpiled JavaScript code

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-2/

Coverage Report Transformer

A utility that transforms JavaScript code coverage data from transpiled/bundled code back to original source file locations using source maps.

Problem Description

Modern JavaScript projects often use transpilers (TypeScript, Babel) and bundlers (webpack, rollup) that transform source code before execution. When collecting code coverage, the coverage data references the transformed code rather than the original source files, making it difficult to understand which parts of the original code are covered.

Your task is to build a coverage transformer that:

  1. Accepts coverage data in Istanbul format
  2. Uses source maps to transform coverage locations back to original source files
  3. Returns transformed coverage data that references the original source code

Requirements

Core Functionality

The transformer should:

  • Create a source map store that manages source map data
  • Accept and transform coverage maps containing coverage for transpiled files
  • Handle coverage data that includes embedded source maps (via inputSourceMap property)
  • Transform statement, function, and branch coverage locations from generated code back to original source locations
  • Return a new coverage map with transformed data referencing original source files

Input Format

The coverage data will be in Istanbul's CoverageMap format, with individual file coverage potentially containing an inputSourceMap property:

{
  "/path/to/generated/file.js": {
    path: "/path/to/generated/file.js",
    statementMap: { ... },
    fnMap: { ... },
    branchMap: { ... },
    s: { ... },
    f: { ... },
    b: { ... },
    inputSourceMap: { /* source map object */ }
  }
}

Output Format

The transformed coverage should reference original source files:

{
  "/path/to/original/file.ts": {
    path: "/path/to/original/file.ts",
    statementMap: { /* transformed locations */ },
    fnMap: { /* transformed locations */ },
    branchMap: { /* transformed locations */ },
    s: { ... },
    f: { ... },
    b: { ... }
  }
}

Implementation

@generates

API

/**
 * Transforms coverage data from transpiled code to original source locations
 *
 * @param {Object} coverageData - Coverage map object containing coverage for one or more files
 * @returns {Promise<Object>} Transformed coverage map with original source file references
 */
async function transformCoverage(coverageData) {
  // IMPLEMENTATION HERE
}

module.exports = { transformCoverage };

Test Cases

Basic transformation

  • Given coverage data for a transpiled file with an embedded source map, transformCoverage() returns coverage data that references the original source file path @test

Multiple files transformation

  • Given coverage data for multiple transpiled files each with embedded source maps, transformCoverage() returns coverage data with all files transformed to their original sources @test

Coverage without source maps

  • Given coverage data for a file without source maps, transformCoverage() returns the original coverage data unchanged @test

Dependencies { .dependencies }

istanbul-lib-source-maps { .dependency }

Provides source map support for Istanbul code coverage, enabling transformation of coverage data from transpiled code back to original sources.

istanbul-lib-coverage { .dependency }

Provides core coverage data structures and utilities for working with Istanbul coverage maps.

Install with Tessl CLI

npx tessl i tessl/npm-istanbul-lib-source-maps

tile.json