Source maps support for Istanbul code coverage toolkit, enabling accurate coverage reporting for transpiled JavaScript code
Overall
score
98%
A utility that transforms JavaScript code coverage data from transpiled/bundled code back to original source file locations using source maps.
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:
The transformer should:
inputSourceMap property)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 */ }
}
}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: { ... }
}
}@generates
/**
* 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 };transformCoverage() returns coverage data that references the original source file path @testtransformCoverage() returns coverage data with all files transformed to their original sources @testtransformCoverage() returns the original coverage data unchanged @testProvides source map support for Istanbul code coverage, enabling transformation of coverage data from transpiled code back to original sources.
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-mapsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10