|
1 | 1 | 'use strict';
|
2 | 2 | const {
|
3 | 3 | ArrayFrom,
|
| 4 | + ArrayPrototypeForEach, |
4 | 5 | ArrayPrototypeMap,
|
5 | 6 | ArrayPrototypePush,
|
6 | 7 | JSONParse,
|
@@ -56,12 +57,13 @@ class CoverageLine {
|
56 | 57 | }
|
57 | 58 |
|
58 | 59 | class TestCoverage {
|
59 |
| - constructor(coverageDirectory, originalCoverageDirectory, workingDirectory, excludeGlobs, includeGlobs, thresholds) { |
| 60 | + constructor(coverageDirectory, originalCoverageDirectory, workingDirectory, excludeGlobs, includeGlobs, sourceMaps, thresholds) { |
60 | 61 | this.coverageDirectory = coverageDirectory;
|
61 | 62 | this.originalCoverageDirectory = originalCoverageDirectory;
|
62 | 63 | this.workingDirectory = workingDirectory;
|
63 | 64 | this.excludeGlobs = excludeGlobs;
|
64 | 65 | this.includeGlobs = includeGlobs;
|
| 66 | + this.sourceMaps = sourceMaps; |
65 | 67 | this.thresholds = thresholds;
|
66 | 68 | }
|
67 | 69 |
|
@@ -364,7 +366,13 @@ class TestCoverage {
|
364 | 366 | this.getLines(data.sources[j], data.sourcesContent[j]);
|
365 | 367 | }
|
366 | 368 | }
|
| 369 | + |
367 | 370 | const sourceMap = new SourceMap(data, { __proto__: null, lineLengths });
|
| 371 | + const linesToCover = new SafeSet(); |
| 372 | + |
| 373 | + for (let i = 0; i < sourceMap[kMappings].length; i++) { |
| 374 | + linesToCover.add(sourceMap[kMappings][i][3] + 1); |
| 375 | + } |
368 | 376 |
|
369 | 377 | for (let j = 0; j < functions.length; ++j) {
|
370 | 378 | const { ranges, functionName, isBlockCoverage } = functions[j];
|
@@ -413,6 +421,15 @@ class TestCoverage {
|
413 | 421 | // No mappable ranges. Skip the function.
|
414 | 422 | continue;
|
415 | 423 | }
|
| 424 | + |
| 425 | + if (this.sourceMaps) { |
| 426 | + ArrayPrototypeForEach(this.getLines(newUrl), (mappedLine) => { |
| 427 | + if (!linesToCover.has(mappedLine.line)) { |
| 428 | + mappedLine.ignore = true; |
| 429 | + } |
| 430 | + }); |
| 431 | + } |
| 432 | + |
416 | 433 | const newScript = newResult.get(newUrl) ?? { __proto__: null, url: newUrl, functions: [] };
|
417 | 434 | ArrayPrototypePush(newScript.functions, { __proto__: null, functionName, ranges: newRanges, isBlockCoverage });
|
418 | 435 | newResult.set(newUrl, newScript);
|
@@ -515,6 +532,7 @@ function setupCoverage(options) {
|
515 | 532 | cwd,
|
516 | 533 | options.coverageExcludeGlobs,
|
517 | 534 | options.coverageIncludeGlobs,
|
| 535 | + options.sourceMaps, |
518 | 536 | {
|
519 | 537 | __proto__: null,
|
520 | 538 | line: options.lineCoverage,
|
|
0 commit comments