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 Sep 30, 2024
1 parent e225f00 commit 76f2fd2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 14 additions & 0 deletions 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 @@ -365,6 +366,12 @@ class TestCoverage {
}
}
const sourceMap = new SourceMap(data, { __proto__: null, lineLengths });
const linesToCover = new SafeSet();

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

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

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
8 changes: 4 additions & 4 deletions test/parallel/test-runner-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@ test('coverage with source maps', skipIfNoInspector, () => {
'# --------------------------------------------------------------',
'# file | line % | branch % | funcs % | uncovered lines',
'# --------------------------------------------------------------',
'# a.test.ts | 53.85 | 100.00 | 100.00 | 8-13', // part of a bundle
'# b.test.ts | 55.56 | 100.00 | 100.00 | 1 7-9', // part of a bundle
'# a.test.ts | 100.00 | 100.00 | 100.00 | ', // part of a bundle
'# b.test.ts | 88.89 | 100.00 | 100.00 | 1', // part of a bundle
'# index.test.js | 71.43 | 66.67 | 100.00 | 6-7', // no source map
'# stdin.test.ts | 57.14 | 100.00 | 100.00 | 4-6', // Source map without original file
'# stdin.test.ts | 100.00 | 100.00 | 100.00 | ', // Source map with original file
'# --------------------------------------------------------------',
'# all files | 58.33 | 87.50 | 100.00 | ',
'# all files | 91.67 | 87.50 | 100.00 | ',
'# --------------------------------------------------------------',
'# end of coverage report',
].join('\n');
Expand Down

0 comments on commit 76f2fd2

Please sign in to comment.