@@ -59,18 +59,10 @@ class CoverageLine { |
59 | 59 | class TestCoverage { |
60 | 60 | constructor(coverageDirectory, |
61 | 61 | originalCoverageDirectory, |
62 | | - workingDirectory, |
63 | | - excludeGlobs, |
64 | | - includeGlobs, |
65 | | - sourceMaps, |
66 | | - thresholds) { |
| 62 | + options) { |
67 | 63 | this.coverageDirectory = coverageDirectory; |
68 | 64 | this.originalCoverageDirectory = originalCoverageDirectory; |
69 | | - this.workingDirectory = workingDirectory; |
70 | | - this.excludeGlobs = excludeGlobs; |
71 | | - this.includeGlobs = includeGlobs; |
72 | | - this.sourceMaps = sourceMaps; |
73 | | - this.thresholds = thresholds; |
| 65 | + this.options = options; |
74 | 66 | } |
75 | 67 |
|
76 | 68 | #sourceLines = new SafeMap(); |
@@ -143,7 +135,7 @@ class TestCoverage { |
143 | 135 | const coverage = this.getCoverageFromDirectory(); |
144 | 136 | const coverageSummary = { |
145 | 137 | __proto__: null, |
146 | | - workingDirectory: this.workingDirectory, |
| 138 | + workingDirectory: this.options.cwd, |
147 | 139 | files: [], |
148 | 140 | totals: { |
149 | 141 | __proto__: null, |
@@ -157,7 +149,12 @@ class TestCoverage { |
157 | 149 | coveredBranchPercent: 0, |
158 | 150 | coveredFunctionPercent: 0, |
159 | 151 | }, |
160 | | - thresholds: this.thresholds, |
| 152 | + thresholds: { |
| 153 | + __proto__: null, |
| 154 | + line: this.options.lineCoverage, |
| 155 | + branch: this.options.branchCoverage, |
| 156 | + function: this.options.functionCoverage, |
| 157 | + }, |
161 | 158 | }; |
162 | 159 |
|
163 | 160 | if (!coverage) { |
@@ -348,7 +345,7 @@ class TestCoverage { |
348 | 345 | mapCoverageWithSourceMap(coverage) { |
349 | 346 | const { result } = coverage; |
350 | 347 | const sourceMapCache = coverage['source-map-cache']; |
351 | | - if (!this.sourceMaps || !sourceMapCache) { |
| 348 | + if (!this.options.sourceMaps || !sourceMapCache) { |
352 | 349 | return result; |
353 | 350 | } |
354 | 351 | const newResult = new SafeMap(); |
@@ -462,21 +459,24 @@ class TestCoverage { |
462 | 459 | if (!StringPrototypeStartsWith(url, 'file:')) return true; |
463 | 460 |
|
464 | 461 | const absolutePath = fileURLToPath(url); |
465 | | - const relativePath = relative(this.workingDirectory, absolutePath); |
466 | | - |
| 462 | + const relativePath = relative(this.options.cwd, absolutePath); |
| 463 | + const { |
| 464 | + coverageExcludeGlobs: excludeGlobs, |
| 465 | + coverageIncludeGlobs: includeGlobs, |
| 466 | + } = this.options; |
467 | 467 | // This check filters out files that match the exclude globs. |
468 | | - if (this.excludeGlobs?.length > 0) { |
469 | | - for (let i = 0; i < this.excludeGlobs.length; ++i) { |
470 | | - if (matchesGlob(relativePath, this.excludeGlobs[i]) || |
471 | | - matchesGlob(absolutePath, this.excludeGlobs[i])) return true; |
| 468 | + if (excludeGlobs?.length > 0) { |
| 469 | + for (let i = 0; i < excludeGlobs.length; ++i) { |
| 470 | + if (matchesGlob(relativePath, excludeGlobs[i]) || |
| 471 | + matchesGlob(absolutePath, excludeGlobs[i])) return true; |
472 | 472 | } |
473 | 473 | } |
474 | 474 |
|
475 | 475 | // This check filters out files that do not match the include globs. |
476 | | - if (this.includeGlobs?.length > 0) { |
477 | | - for (let i = 0; i < this.includeGlobs.length; ++i) { |
478 | | - if (matchesGlob(relativePath, this.includeGlobs[i]) || |
479 | | - matchesGlob(absolutePath, this.includeGlobs[i])) return false; |
| 476 | + if (includeGlobs?.length > 0) { |
| 477 | + for (let i = 0; i < includeGlobs.length; ++i) { |
| 478 | + if (matchesGlob(relativePath, includeGlobs[i]) || |
| 479 | + matchesGlob(absolutePath, includeGlobs[i])) return false; |
480 | 480 | } |
481 | 481 | return true; |
482 | 482 | } |
@@ -518,16 +518,7 @@ function setupCoverage(options) { |
518 | 518 | return new TestCoverage( |
519 | 519 | coverageDirectory, |
520 | 520 | originalCoverageDirectory, |
521 | | - options.cwd, |
522 | | - options.coverageExcludeGlobs, |
523 | | - options.coverageIncludeGlobs, |
524 | | - options.sourceMaps, |
525 | | - { |
526 | | - __proto__: null, |
527 | | - line: options.lineCoverage, |
528 | | - branch: options.branchCoverage, |
529 | | - function: options.functionCoverage, |
530 | | - }, |
| 521 | + options, |
531 | 522 | ); |
532 | 523 | } |
533 | 524 |
|
|