Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: ignore unmapped lines for coverage #55162

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
geeksilva97 marked this conversation as resolved.
Show resolved Hide resolved
}

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 without 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
Loading