@@ -25,9 +25,9 @@ const {
2525 readFileSync,
2626 rmSync,
2727} = require ( 'fs' ) ;
28- const { setupCoverageHooks } = require ( 'internal/util' ) ;
28+ const { setupCoverageHooks, isWindows , isMacOS } = 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 {
@@ -42,6 +42,25 @@ const kLineEndingRegex = /\r?\n$/u;
4242const kLineSplitRegex = / (?< = \r ? \n ) / u;
4343const kStatusRegex = / \/ \* n o d e : c o v e r a g e (?< status > e n a b l e | d i s a b l e ) \* \/ / ;
4444
45+ let minimatch ;
46+ function lazyMinimatch ( ) {
47+ minimatch ??= require ( 'internal/deps/minimatch/index' ) ;
48+ return minimatch ;
49+ }
50+
51+ function glob ( path , pattern , windows ) {
52+ return lazyMinimatch ( ) . minimatch ( path , pattern , {
53+ __proto__ : null ,
54+ nocase : isMacOS || isWindows ,
55+ windowsPathsNoEscape : true ,
56+ nonegate : true ,
57+ nocomment : true ,
58+ optimizationLevel : 2 ,
59+ platform : windows ? 'win32' : 'posix' ,
60+ nocaseMagicOnly : true ,
61+ } ) ;
62+ }
63+
4564class CoverageLine {
4665 constructor ( line , startOffset , src , length = src ?. length ) {
4766 const newlineLength = src == null ? 0 :
@@ -464,23 +483,24 @@ class TestCoverage {
464483 coverageExcludeGlobs : excludeGlobs ,
465484 coverageIncludeGlobs : includeGlobs ,
466485 } = this . options ;
467- // This check filters out files that match the exclude globs.
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- }
473- }
474486
475487 // This check filters out files that do not match the include globs.
476488 if ( includeGlobs ?. length > 0 ) {
477489 for ( let i = 0 ; i < includeGlobs . length ; ++ i ) {
478- if ( matchesGlob ( relativePath , includeGlobs [ i ] ) ||
479- matchesGlob ( absolutePath , includeGlobs [ i ] ) ) return false ;
490+ if ( glob ( relativePath , includeGlobs [ i ] ) ||
491+ glob ( absolutePath , includeGlobs [ i ] ) ) return false ;
480492 }
481493 return true ;
482494 }
483495
496+ // This check filters out files that match the exclude globs.
497+ if ( excludeGlobs ?. length > 0 ) {
498+ for ( let i = 0 ; i < excludeGlobs . length ; ++ i ) {
499+ if ( glob ( relativePath , excludeGlobs [ i ] ) ||
500+ glob ( absolutePath , excludeGlobs [ i ] ) ) return true ;
501+ }
502+ }
503+
484504 // This check filters out the node_modules/ directory, unless it is explicitly included.
485505 return StringPrototypeIncludes ( url , '/node_modules/' ) ;
486506 }
0 commit comments