Skip to content

Commit a5b8a67

Browse files
committed
test_runner: ignore unmappes lines for coverage
1 parent e225f00 commit a5b8a67

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/internal/test_runner/coverage.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const {
33
ArrayFrom,
4+
ArrayPrototypeForEach,
45
ArrayPrototypeMap,
56
ArrayPrototypePush,
67
JSONParse,
@@ -365,6 +366,12 @@ class TestCoverage {
365366
}
366367
}
367368
const sourceMap = new SourceMap(data, { __proto__: null, lineLengths });
369+
const linesToCover = new SafeSet();
370+
371+
for (let i = 0; i< sourceMap[kMappings].length; i++) {
372+
const { 3: originalLine } = sourceMap[kMappings][i];
373+
linesToCover.add(originalLine + 1);
374+
}
368375

369376
for (let j = 0; j < functions.length; ++j) {
370377
const { ranges, functionName, isBlockCoverage } = functions[j];
@@ -413,6 +420,13 @@ class TestCoverage {
413420
// No mappable ranges. Skip the function.
414421
continue;
415422
}
423+
424+
ArrayPrototypeForEach(this.getLines(newUrl), (mappedLine) => {
425+
if (!linesToCover.has(mappedLine.line)) {
426+
mappedLine.ignore = true;
427+
}
428+
});
429+
416430
const newScript = newResult.get(newUrl) ?? { __proto__: null, url: newUrl, functions: [] };
417431
ArrayPrototypePush(newScript.functions, { __proto__: null, functionName, ranges: newRanges, isBlockCoverage });
418432
newResult.set(newUrl, newScript);

test/parallel/test-runner-coverage.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,12 @@ test('coverage with source maps', skipIfNoInspector, () => {
296296
'# --------------------------------------------------------------',
297297
'# file | line % | branch % | funcs % | uncovered lines',
298298
'# --------------------------------------------------------------',
299-
'# a.test.ts | 53.85 | 100.00 | 100.00 | 8-13', // part of a bundle
300-
'# b.test.ts | 55.56 | 100.00 | 100.00 | 1 7-9', // part of a bundle
299+
'# a.test.ts | 100.00 | 100.00 | 100.00 | ', // part of a bundle
300+
'# b.test.ts | 88.89 | 100.00 | 100.00 | 1', // part of a bundle
301301
'# index.test.js | 71.43 | 66.67 | 100.00 | 6-7', // no source map
302-
'# stdin.test.ts | 57.14 | 100.00 | 100.00 | 4-6', // Source map without original file
302+
'# stdin.test.ts | 100.00 | 100.00 | 100.00 | ', // Source map with original file
303303
'# --------------------------------------------------------------',
304-
'# all files | 58.33 | 87.50 | 100.00 | ',
304+
'# all files | 91.67 | 87.50 | 100.00 | ',
305305
'# --------------------------------------------------------------',
306306
'# end of coverage report',
307307
].join('\n');

0 commit comments

Comments
 (0)