1
1
'use strict' ;
2
2
const {
3
+ ArrayPrototypeMap,
3
4
ArrayPrototypePush,
4
5
ArrayPrototypeReduce,
5
6
ArrayPrototypeShift,
6
7
ArrayPrototypeSlice,
8
+ ArrayPrototypeSome,
7
9
ArrayPrototypeUnshift,
8
10
FunctionPrototype,
9
11
MathMax,
@@ -12,6 +14,7 @@ const {
12
14
PromisePrototypeThen,
13
15
PromiseResolve,
14
16
ReflectApply,
17
+ RegExpPrototypeExec,
15
18
SafeMap,
16
19
SafeSet,
17
20
SafePromiseAll,
@@ -30,7 +33,11 @@ const {
30
33
} = require ( 'internal/errors' ) ;
31
34
const { getOptionValue } = require ( 'internal/options' ) ;
32
35
const { 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' ) ;
34
41
const {
35
42
createDeferredPromise,
36
43
kEmptyObject,
@@ -58,6 +65,13 @@ const kDefaultTimeout = null;
58
65
const noop = FunctionPrototype ;
59
66
const isTestRunner = getOptionValue ( '--test' ) ;
60
67
const 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 ;
61
75
const kShouldAbort = Symbol ( 'kShouldAbort' ) ;
62
76
const kRunHook = Symbol ( 'kRunHook' ) ;
63
77
const kHookNames = ObjectSeal ( [ 'before' , 'after' , 'beforeEach' , 'afterEach' ] ) ;
@@ -195,6 +209,18 @@ class Test extends AsyncResource {
195
209
this . timeout = timeout ;
196
210
}
197
211
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
+
198
224
if ( testOnlyFlag && ! this . only ) {
199
225
skip = '\'only\' option not set' ;
200
226
}
@@ -210,7 +236,6 @@ class Test extends AsyncResource {
210
236
validateAbortSignal ( signal , 'options.signal' ) ;
211
237
this . #outerSignal?. addEventListener ( 'abort' , this . #abortHandler) ;
212
238
213
-
214
239
this . fn = fn ;
215
240
this . name = name ;
216
241
this . parent = parent ;
@@ -669,6 +694,7 @@ class ItTest extends Test {
669
694
return { ctx : { signal : this . signal , name : this . name } , args : [ ] } ;
670
695
}
671
696
}
697
+
672
698
class Suite extends Test {
673
699
constructor ( options ) {
674
700
super ( options ) ;
@@ -704,7 +730,6 @@ class Suite extends Test {
704
730
return ;
705
731
}
706
732
707
-
708
733
const hookArgs = this . getRunArgs ( ) ;
709
734
await this [ kRunHook ] ( 'before' , hookArgs ) ;
710
735
const stopPromise = stopTest ( this . timeout , this . signal ) ;
0 commit comments