|
1 | 1 | 'use strict'; |
2 | 2 | const { |
3 | 3 | ArrayFrom, |
| 4 | + ArrayPrototypeForEach, |
4 | 5 | ArrayPrototypeMap, |
5 | 6 | ArrayPrototypePush, |
6 | 7 | JSONParse, |
@@ -57,12 +58,21 @@ class CoverageLine { |
57 | 58 | } |
58 | 59 |
|
59 | 60 | class TestCoverage { |
60 | | - constructor(coverageDirectory, originalCoverageDirectory, workingDirectory, excludeGlobs, includeGlobs, thresholds) { |
| 61 | + constructor( |
| 62 | + coverageDirectory, |
| 63 | + originalCoverageDirectory, |
| 64 | + workingDirectory, |
| 65 | + excludeGlobs, |
| 66 | + includeGlobs, |
| 67 | + sourceMaps, |
| 68 | + thresholds, |
| 69 | + ) { |
61 | 70 | this.coverageDirectory = coverageDirectory; |
62 | 71 | this.originalCoverageDirectory = originalCoverageDirectory; |
63 | 72 | this.workingDirectory = workingDirectory; |
64 | 73 | this.excludeGlobs = excludeGlobs; |
65 | 74 | this.includeGlobs = includeGlobs; |
| 75 | + this.sourceMaps = sourceMaps; |
66 | 76 | this.thresholds = thresholds; |
67 | 77 | } |
68 | 78 |
|
@@ -366,7 +376,13 @@ class TestCoverage { |
366 | 376 | this.getLines(data.sources[j], data.sourcesContent[j]); |
367 | 377 | } |
368 | 378 | } |
| 379 | + |
369 | 380 | const sourceMap = new SourceMap(data, { __proto__: null, lineLengths }); |
| 381 | + const linesToCover = new SafeSet(); |
| 382 | + |
| 383 | + for (let i = 0; i < sourceMap[kMappings].length; i++) { |
| 384 | + linesToCover.add(sourceMap[kMappings][i][3] + 1); |
| 385 | + } |
370 | 386 |
|
371 | 387 | for (let j = 0; j < functions.length; ++j) { |
372 | 388 | const { ranges, functionName, isBlockCoverage } = functions[j]; |
@@ -415,6 +431,15 @@ class TestCoverage { |
415 | 431 | // No mappable ranges. Skip the function. |
416 | 432 | continue; |
417 | 433 | } |
| 434 | + |
| 435 | + if (this.sourceMaps) { |
| 436 | + ArrayPrototypeForEach(this.getLines(newUrl), (mappedLine) => { |
| 437 | + if (!linesToCover.has(mappedLine.line)) { |
| 438 | + mappedLine.ignore = true; |
| 439 | + } |
| 440 | + }); |
| 441 | + } |
| 442 | + |
418 | 443 | const newScript = newResult.get(newUrl) ?? { __proto__: null, url: newUrl, functions: [] }; |
419 | 444 | ArrayPrototypePush(newScript.functions, { __proto__: null, functionName, ranges: newRanges, isBlockCoverage }); |
420 | 445 | newResult.set(newUrl, newScript); |
@@ -516,6 +541,7 @@ function setupCoverage(options) { |
516 | 541 | options.cwd, |
517 | 542 | options.coverageExcludeGlobs, |
518 | 543 | options.coverageIncludeGlobs, |
| 544 | + options.sourceMaps, |
519 | 545 | { |
520 | 546 | __proto__: null, |
521 | 547 | line: options.lineCoverage, |
|
0 commit comments