@@ -84,6 +84,7 @@ const {
84
84
forceExit,
85
85
sourceMaps,
86
86
testNamePatterns,
87
+ testSkipPatterns,
87
88
testOnlyFlag,
88
89
} = parseCommandLine ( ) ;
89
90
let kResistStopPropagation ;
@@ -137,6 +138,19 @@ function stopTest(timeout, signal) {
137
138
return deferred . promise ;
138
139
}
139
140
141
+ function testMatchesPattern ( test , patterns ) {
142
+ const matchesByNameOrParent = ArrayPrototypeSome ( patterns , ( re ) =>
143
+ RegExpPrototypeExec ( re , test . name ) !== null ,
144
+ ) || ( test . parent && testMatchesPattern ( test . parent , patterns ) ) ;
145
+ if ( matchesByNameOrParent ) return true ;
146
+
147
+ const testNameWithAncestors = StringPrototypeTrim ( test . getTestNameWithAncestors ( ) ) ;
148
+
149
+ return ArrayPrototypeSome ( patterns , ( re ) =>
150
+ RegExpPrototypeExec ( re , testNameWithAncestors ) !== null ,
151
+ ) ;
152
+ }
153
+
140
154
class TestContext {
141
155
#test;
142
156
@@ -300,8 +314,7 @@ class Test extends AsyncResource {
300
314
ownAfterEachCount : 0 ,
301
315
} ;
302
316
303
- if ( ( testNamePatterns !== null && ! this . matchesTestNamePatterns ( ) ) ||
304
- ( testOnlyFlag && ! this . only ) ) {
317
+ if ( this . willBeFiltered ( ) ) {
305
318
this . filtered = true ;
306
319
this . parent . filteredSubtestCount ++ ;
307
320
}
@@ -408,18 +421,16 @@ class Test extends AsyncResource {
408
421
}
409
422
}
410
423
411
- matchesTestNamePatterns ( ) {
412
- const matchesByNameOrParent = ArrayPrototypeSome ( testNamePatterns , ( re ) =>
413
- RegExpPrototypeExec ( re , this . name ) !== null ,
414
- ) ||
415
- this . parent ?. matchesTestNamePatterns ( ) ;
416
-
417
- if ( matchesByNameOrParent ) return true ;
424
+ willBeFiltered ( ) {
425
+ if ( testOnlyFlag && ! this . only ) return true ;
418
426
419
- const testNameWithAncestors = StringPrototypeTrim ( this . getTestNameWithAncestors ( ) ) ;
420
- if ( ! testNameWithAncestors ) return false ;
421
-
422
- return ArrayPrototypeSome ( testNamePatterns , ( re ) => RegExpPrototypeExec ( re , testNameWithAncestors ) !== null ) ;
427
+ if ( testNamePatterns && ! testMatchesPattern ( this , testNamePatterns ) ) {
428
+ return true ;
429
+ }
430
+ if ( testSkipPatterns && testMatchesPattern ( this , testSkipPatterns ) ) {
431
+ return true ;
432
+ }
433
+ return false ;
423
434
}
424
435
425
436
/**
@@ -987,8 +998,8 @@ class TestHook extends Test {
987
998
getRunArgs ( ) {
988
999
return this . #args;
989
1000
}
990
- matchesTestNamePatterns ( ) {
991
- return true ;
1001
+ willBeFiltered ( ) {
1002
+ return false ;
992
1003
}
993
1004
postRun ( ) {
994
1005
const { error, loc, parentTest : parent } = this ;
@@ -1016,7 +1027,7 @@ class Suite extends Test {
1016
1027
constructor ( options ) {
1017
1028
super ( options ) ;
1018
1029
1019
- if ( testNamePatterns !== null && ! options . skip ) {
1030
+ if ( testNamePatterns !== null && testSkipPatterns !== null && ! options . skip ) {
1020
1031
this . fn = options . fn || this . fn ;
1021
1032
this . skipped = false ;
1022
1033
}
@@ -1050,7 +1061,12 @@ class Suite extends Test {
1050
1061
// tests that it contains - in case of children matching patterns.
1051
1062
this . filtered = false ;
1052
1063
this . parent . filteredSubtestCount -- ;
1053
- } else if ( testOnlyFlag && testNamePatterns == null && this . filteredSubtestCount === this . subtests . length ) {
1064
+ } else if (
1065
+ testOnlyFlag &&
1066
+ testNamePatterns == null &&
1067
+ testSkipPatterns == null &&
1068
+ this . filteredSubtestCount === this . subtests . length
1069
+ ) {
1054
1070
// If no subtests are marked as "only", run them all
1055
1071
this . filteredSubtestCount = 0 ;
1056
1072
}
0 commit comments