Skip to content

Commit

Permalink
test_runner: pass options directly to TestCoverage
Browse files Browse the repository at this point in the history
PR-URL: nodejs#55578
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Raz Luvaton <[email protected]>
  • Loading branch information
RedYetiDev authored and louwers committed Nov 2, 2024
1 parent 97fdb41 commit 0048032
Showing 1 changed file with 24 additions and 33 deletions.
57 changes: 24 additions & 33 deletions lib/internal/test_runner/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,10 @@ class CoverageLine {
class TestCoverage {
constructor(coverageDirectory,
originalCoverageDirectory,
workingDirectory,
excludeGlobs,
includeGlobs,
sourceMaps,
thresholds) {
options) {
this.coverageDirectory = coverageDirectory;
this.originalCoverageDirectory = originalCoverageDirectory;
this.workingDirectory = workingDirectory;
this.excludeGlobs = excludeGlobs;
this.includeGlobs = includeGlobs;
this.sourceMaps = sourceMaps;
this.thresholds = thresholds;
this.options = options;
}

#sourceLines = new SafeMap();
Expand Down Expand Up @@ -143,7 +135,7 @@ class TestCoverage {
const coverage = this.getCoverageFromDirectory();
const coverageSummary = {
__proto__: null,
workingDirectory: this.workingDirectory,
workingDirectory: this.options.cwd,
files: [],
totals: {
__proto__: null,
Expand All @@ -157,7 +149,12 @@ class TestCoverage {
coveredBranchPercent: 0,
coveredFunctionPercent: 0,
},
thresholds: this.thresholds,
thresholds: {
__proto__: null,
line: this.options.lineCoverage,
branch: this.options.branchCoverage,
function: this.options.functionCoverage,
},
};

if (!coverage) {
Expand Down Expand Up @@ -348,7 +345,7 @@ class TestCoverage {
mapCoverageWithSourceMap(coverage) {
const { result } = coverage;
const sourceMapCache = coverage['source-map-cache'];
if (!this.sourceMaps || !sourceMapCache) {
if (!this.options.sourceMaps || !sourceMapCache) {
return result;
}
const newResult = new SafeMap();
Expand Down Expand Up @@ -462,21 +459,24 @@ class TestCoverage {
if (!StringPrototypeStartsWith(url, 'file:')) return true;

const absolutePath = fileURLToPath(url);
const relativePath = relative(this.workingDirectory, absolutePath);

const relativePath = relative(this.options.cwd, absolutePath);
const {
coverageExcludeGlobs: excludeGlobs,
coverageIncludeGlobs: includeGlobs,
} = this.options;
// This check filters out files that match the exclude globs.
if (this.excludeGlobs?.length > 0) {
for (let i = 0; i < this.excludeGlobs.length; ++i) {
if (matchesGlob(relativePath, this.excludeGlobs[i]) ||
matchesGlob(absolutePath, this.excludeGlobs[i])) return true;
if (excludeGlobs?.length > 0) {
for (let i = 0; i < excludeGlobs.length; ++i) {
if (matchesGlob(relativePath, excludeGlobs[i]) ||
matchesGlob(absolutePath, excludeGlobs[i])) return true;
}
}

// This check filters out files that do not match the include globs.
if (this.includeGlobs?.length > 0) {
for (let i = 0; i < this.includeGlobs.length; ++i) {
if (matchesGlob(relativePath, this.includeGlobs[i]) ||
matchesGlob(absolutePath, this.includeGlobs[i])) return false;
if (includeGlobs?.length > 0) {
for (let i = 0; i < includeGlobs.length; ++i) {
if (matchesGlob(relativePath, includeGlobs[i]) ||
matchesGlob(absolutePath, includeGlobs[i])) return false;
}
return true;
}
Expand Down Expand Up @@ -518,16 +518,7 @@ function setupCoverage(options) {
return new TestCoverage(
coverageDirectory,
originalCoverageDirectory,
options.cwd,
options.coverageExcludeGlobs,
options.coverageIncludeGlobs,
options.sourceMaps,
{
__proto__: null,
line: options.lineCoverage,
branch: options.branchCoverage,
function: options.functionCoverage,
},
options,
);
}

Expand Down

0 comments on commit 0048032

Please sign in to comment.