test_runner: exclude test files from coverage by default · nodejs/node@ea9a675

@@ -27,7 +27,7 @@ const {

2727

} = require('fs');

2828

const { setupCoverageHooks } = require('internal/util');

2929

const { tmpdir } = require('os');

30-

const { join, resolve, relative, matchesGlob } = require('path');

30+

const { join, resolve, relative } = require('path');

3131

const { fileURLToPath } = require('internal/url');

3232

const { kMappings, SourceMap } = require('internal/source_map/source_map');

3333

const {

@@ -36,6 +36,8 @@ const {

3636

ERR_SOURCE_MAP_MISSING_SOURCE,

3737

},

3838

} = require('internal/errors');

39+

const { matchGlobPattern } = require('internal/fs/glob');

40+3941

const kCoverageFileRegex = /^coverage-(\d+)-(\d{13})-(\d+)\.json$/;

4042

const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;

4143

const kLineEndingRegex = /\r?\n$/u;

@@ -464,19 +466,24 @@ class TestCoverage {

464466

coverageExcludeGlobs: excludeGlobs,

465467

coverageIncludeGlobs: includeGlobs,

466468

} = this.options;

469+467470

// This check filters out files that match the exclude globs.

468471

if (excludeGlobs?.length > 0) {

469472

for (let i = 0; i < excludeGlobs.length; ++i) {

470-

if (matchesGlob(relativePath, excludeGlobs[i]) ||

471-

matchesGlob(absolutePath, excludeGlobs[i])) return true;

473+

if (

474+

matchGlobPattern(relativePath, excludeGlobs[i]) ||

475+

matchGlobPattern(absolutePath, excludeGlobs[i])

476+

) return true;

472477

}

473478

}

474479475480

// This check filters out files that do not match the include globs.

476481

if (includeGlobs?.length > 0) {

477482

for (let i = 0; i < includeGlobs.length; ++i) {

478-

if (matchesGlob(relativePath, includeGlobs[i]) ||

479-

matchesGlob(absolutePath, includeGlobs[i])) return false;

483+

if (

484+

matchGlobPattern(relativePath, includeGlobs[i]) ||

485+

matchGlobPattern(absolutePath, includeGlobs[i])

486+

) return false;

480487

}

481488

return true;

482489

}