11'use strict' ;
22const {
3+ ArrayPrototypeMap,
34 ArrayPrototypePush,
45 ArrayPrototypeReduce,
56 ArrayPrototypeShift,
67 ArrayPrototypeSlice,
8+ ArrayPrototypeSome,
79 ArrayPrototypeUnshift,
810 FunctionPrototype,
911 MathMax,
@@ -12,6 +14,7 @@ const {
1214 PromisePrototypeThen,
1315 PromiseResolve,
1416 ReflectApply,
17+ RegExpPrototypeExec,
1518 SafeMap,
1619 SafeSet,
1720 SafePromiseAll,
@@ -30,7 +33,11 @@ const {
3033} = require ( 'internal/errors' ) ;
3134const { getOptionValue } = require ( 'internal/options' ) ;
3235const { TapStream } = require ( 'internal/test_runner/tap_stream' ) ;
33- const { createDeferredCallback, isTestFailureError } = require ( 'internal/test_runner/utils' ) ;
36+ const {
37+ convertStringToRegExp,
38+ createDeferredCallback,
39+ isTestFailureError,
40+ } = require ( 'internal/test_runner/utils' ) ;
3441const {
3542 createDeferredPromise,
3643 kEmptyObject,
@@ -58,6 +65,13 @@ const kDefaultTimeout = null;
5865const noop = FunctionPrototype ;
5966const isTestRunner = getOptionValue ( '--test' ) ;
6067const testOnlyFlag = ! isTestRunner && getOptionValue ( '--test-only' ) ;
68+ const testNamePatternFlag = isTestRunner ? null :
69+ getOptionValue ( '--test-name-pattern' ) ;
70+ const testNamePatterns = testNamePatternFlag ?. length > 0 ?
71+ ArrayPrototypeMap (
72+ testNamePatternFlag ,
73+ ( re ) => convertStringToRegExp ( re , '--test-name-pattern' )
74+ ) : null ;
6175const kShouldAbort = Symbol ( 'kShouldAbort' ) ;
6276const kRunHook = Symbol ( 'kRunHook' ) ;
6377const kHookNames = ObjectSeal ( [ 'before' , 'after' , 'beforeEach' , 'afterEach' ] ) ;
@@ -195,6 +209,18 @@ class Test extends AsyncResource {
195209 this . timeout = timeout ;
196210 }
197211
212+ if ( testNamePatterns !== null ) {
213+ // eslint-disable-next-line no-use-before-define
214+ const match = this instanceof TestHook || ArrayPrototypeSome (
215+ testNamePatterns ,
216+ ( re ) => RegExpPrototypeExec ( re , name ) !== null
217+ ) ;
218+
219+ if ( ! match ) {
220+ skip = 'test name does not match pattern' ;
221+ }
222+ }
223+
198224 if ( testOnlyFlag && ! this . only ) {
199225 skip = '\'only\' option not set' ;
200226 }
@@ -210,7 +236,6 @@ class Test extends AsyncResource {
210236 validateAbortSignal ( signal , 'options.signal' ) ;
211237 this . #outerSignal?. addEventListener ( 'abort' , this . #abortHandler) ;
212238
213-
214239 this . fn = fn ;
215240 this . name = name ;
216241 this . parent = parent ;
@@ -669,6 +694,7 @@ class ItTest extends Test {
669694 return { ctx : { signal : this . signal , name : this . name } , args : [ ] } ;
670695 }
671696}
697+
672698class Suite extends Test {
673699 constructor ( options ) {
674700 super ( options ) ;
@@ -704,7 +730,6 @@ class Suite extends Test {
704730 return ;
705731 }
706732
707-
708733 const hookArgs = this . getRunArgs ( ) ;
709734 await this [ kRunHook ] ( 'before' , hookArgs ) ;
710735 const stopPromise = stopTest ( this . timeout , this . signal ) ;
0 commit comments