test_runner: exclude test files from coverage by default · nodejs/node@ea9a675
@@ -27,7 +27,7 @@ const {
2727} = require('fs');
2828const { setupCoverageHooks } = require('internal/util');
2929const { tmpdir } = require('os');
30-const { join, resolve, relative, matchesGlob } = require('path');
30+const { join, resolve, relative } = require('path');
3131const { fileURLToPath } = require('internal/url');
3232const { kMappings, SourceMap } = require('internal/source_map/source_map');
3333const {
@@ -36,6 +36,8 @@ const {
3636ERR_SOURCE_MAP_MISSING_SOURCE,
3737},
3838} = require('internal/errors');
39+const { matchGlobPattern } = require('internal/fs/glob');
40+3941const kCoverageFileRegex = /^coverage-(\d+)-(\d{13})-(\d+)\.json$/;
4042const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
4143const kLineEndingRegex = /\r?\n$/u;
@@ -464,19 +466,24 @@ class TestCoverage {
464466coverageExcludeGlobs: excludeGlobs,
465467coverageIncludeGlobs: includeGlobs,
466468} = this.options;
469+467470// This check filters out files that match the exclude globs.
468471if (excludeGlobs?.length > 0) {
469472for (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.
476481if (includeGlobs?.length > 0) {
477482for (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}
481488return true;
482489}