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