Skip to content

Commit 020e62e

Browse files
committed
fixup! test_runner: match dotfiles in default coverage exclude
Signed-off-by: semimikoh <ejffjeosms@gmail.com>
1 parent c241614 commit 020e62e

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

lib/internal/fs/glob.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,13 +927,15 @@ class Glob {
927927
* @param {string} path the path to check
928928
* @param {string} pattern the glob pattern to match
929929
* @param {boolean} windows whether the path is on a Windows system, defaults to `isWindows`
930+
* @param {object} [options] the options for the minimatch module
930931
* @returns {boolean}
931932
*/
932-
function matchGlobPattern(path, pattern, windows = isWindows) {
933+
function matchGlobPattern(path, pattern, windows = isWindows, options = kEmptyObject) {
933934
validateString(path, 'path');
934935
validateString(pattern, 'pattern');
935936
return lazyMinimatch().minimatch(path, pattern, {
936937
kEmptyObject,
938+
...options,
937939
nocase: isMacOS || isWindows,
938940
windowsPathsNoEscape: true,
939941
nonegate: true,

lib/internal/test_runner/coverage.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ const kIgnoreRegex = /\/\* node:coverage ignore next (?<count>\d+ )?\*\//;
4444
const kLineEndingRegex = /\r?\n$/u;
4545
const kLineSplitRegex = /(?<=\r?\n)/u;
4646
const kStatusRegex = /\/\* node:coverage (?<status>enable|disable) \*\//;
47+
const kMatchGlobPatternOptions = { __proto__: null, dot: true };
48+
49+
function matchCoverageGlob(path, pattern) {
50+
return matchGlobPattern(path, pattern, undefined, kMatchGlobPatternOptions);
51+
}
4752

4853
class CoverageLine {
4954
constructor(line, startOffset, src, length = src?.length) {
@@ -481,8 +486,8 @@ class TestCoverage {
481486
if (excludeGlobs?.length > 0) {
482487
for (let i = 0; i < excludeGlobs.length; ++i) {
483488
if (
484-
matchGlobPattern(relativePath, excludeGlobs[i]) ||
485-
matchGlobPattern(absolutePath, excludeGlobs[i])
489+
matchCoverageGlob(relativePath, excludeGlobs[i]) ||
490+
matchCoverageGlob(absolutePath, excludeGlobs[i])
486491
) return true;
487492
}
488493
}
@@ -491,8 +496,8 @@ class TestCoverage {
491496
if (includeGlobs?.length > 0) {
492497
for (let i = 0; i < includeGlobs.length; ++i) {
493498
if (
494-
matchGlobPattern(relativePath, includeGlobs[i]) ||
495-
matchGlobPattern(absolutePath, includeGlobs[i])
499+
matchCoverageGlob(relativePath, includeGlobs[i]) ||
500+
matchCoverageGlob(absolutePath, includeGlobs[i])
496501
) return false;
497502
}
498503
return true;

lib/internal/test_runner/utils.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ if (getOptionValue('--strip-types')) {
7575
ArrayPrototypePush(kFileExtensions, 'ts', 'mts', 'cts');
7676
}
7777
const kDefaultPattern = `**/{${ArrayPrototypeJoin(kPatterns, ',')}}.{${ArrayPrototypeJoin(kFileExtensions, ',')}}`;
78-
const kDefaultCoverageDotfilePattern =
79-
`test/{.*,**/.*}.{${ArrayPrototypeJoin(kFileExtensions, ',')}}`;
8078

8179
function createDeferredCallback() {
8280
let calledCount = 0;
@@ -405,7 +403,7 @@ function parseCommandLine() {
405403
if (!coverageExcludeGlobs || coverageExcludeGlobs.length === 0) {
406404
// TODO(pmarchini): this default should follow something similar to c8 defaults
407405
// Default exclusions should be also exported to be used by other tools / users
408-
coverageExcludeGlobs = [kDefaultPattern, kDefaultCoverageDotfilePattern];
406+
coverageExcludeGlobs = [kDefaultPattern];
409407
}
410408
coverageIncludeGlobs = getOptionValue('--test-coverage-include');
411409

0 commit comments

Comments
 (0)