Skip to content

Commit

Permalink
test_runner: ignore unmapped lines for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksilva97 committed Oct 5, 2024
1 parent 98788da commit 67517de
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/internal/test_runner/coverage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const {
ArrayFrom,
ArrayPrototypeForEach,
ArrayPrototypeMap,
ArrayPrototypePush,
JSONParse,
Expand Down Expand Up @@ -56,12 +57,21 @@ class CoverageLine {
}

class TestCoverage {
constructor(coverageDirectory, originalCoverageDirectory, workingDirectory, excludeGlobs, includeGlobs, thresholds) {
constructor(
coverageDirectory,
originalCoverageDirectory,
workingDirectory,
excludeGlobs,
includeGlobs,
sourceMaps,
thresholds,
) {
this.coverageDirectory = coverageDirectory;
this.originalCoverageDirectory = originalCoverageDirectory;
this.workingDirectory = workingDirectory;
this.excludeGlobs = excludeGlobs;
this.includeGlobs = includeGlobs;
this.sourceMaps = sourceMaps;
this.thresholds = thresholds;
}

Expand Down Expand Up @@ -364,7 +374,13 @@ class TestCoverage {
this.getLines(data.sources[j], data.sourcesContent[j]);
}
}

const sourceMap = new SourceMap(data, { __proto__: null, lineLengths });
const linesToCover = new SafeSet();

for (let i = 0; i < sourceMap[kMappings].length; i++) {
linesToCover.add(sourceMap[kMappings][i][3] + 1);
}

for (let j = 0; j < functions.length; ++j) {
const { ranges, functionName, isBlockCoverage } = functions[j];
Expand Down Expand Up @@ -413,6 +429,15 @@ class TestCoverage {
// No mappable ranges. Skip the function.
continue;
}

if (this.sourceMaps) {
ArrayPrototypeForEach(this.getLines(newUrl), (mappedLine) => {
if (!linesToCover.has(mappedLine.line)) {
mappedLine.ignore = true;
}
});
}

const newScript = newResult.get(newUrl) ?? { __proto__: null, url: newUrl, functions: [] };
ArrayPrototypePush(newScript.functions, { __proto__: null, functionName, ranges: newRanges, isBlockCoverage });
newResult.set(newUrl, newScript);
Expand Down Expand Up @@ -514,6 +539,7 @@ function setupCoverage(options) {
options.cwd,
options.coverageExcludeGlobs,
options.coverageIncludeGlobs,
options.sourceMaps,
{
__proto__: null,
line: options.lineCoverage,
Expand Down

0 comments on commit 67517de

Please sign in to comment.