1
- // https://github.com/nodejs/node/blob/cb7e0c59df10a42cd6930ca7f99d3acee1ce7627 /lib/internal/test_runner/test.js
1
+ // https://github.com/nodejs/node/blob/87170c3f9271da947a7b33d0696ec4cf8aab6eb6 /lib/internal/test_runner/test.js
2
2
3
3
'use strict'
4
4
5
5
const {
6
+ ArrayPrototypeMap,
6
7
ArrayPrototypePush,
7
8
ArrayPrototypeReduce,
8
9
ArrayPrototypeShift,
9
10
ArrayPrototypeSlice,
11
+ ArrayPrototypeSome,
10
12
ArrayPrototypeUnshift,
11
13
FunctionPrototype,
12
14
MathMax,
@@ -15,6 +17,7 @@ const {
15
17
PromisePrototypeThen,
16
18
PromiseResolve,
17
19
ReflectApply,
20
+ RegExpPrototypeExec,
18
21
SafeMap,
19
22
SafeSet,
20
23
SafePromiseAll,
@@ -33,7 +36,11 @@ const {
33
36
} = require ( '#internal/errors' )
34
37
const { getOptionValue } = require ( '#internal/options' )
35
38
const { TapStream } = require ( '#internal/test_runner/tap_stream' )
36
- const { createDeferredCallback, isTestFailureError } = require ( '#internal/test_runner/utils' )
39
+ const {
40
+ convertStringToRegExp,
41
+ createDeferredCallback,
42
+ isTestFailureError
43
+ } = require ( '#internal/test_runner/utils' )
37
44
const {
38
45
createDeferredPromise,
39
46
kEmptyObject
@@ -61,6 +68,15 @@ const kDefaultTimeout = null
61
68
const noop = FunctionPrototype
62
69
const isTestRunner = getOptionValue ( '--test' )
63
70
const testOnlyFlag = ! isTestRunner && getOptionValue ( '--test-only' )
71
+ const testNamePatternFlag = isTestRunner
72
+ ? null
73
+ : getOptionValue ( '--test-name-pattern' )
74
+ const testNamePatterns = testNamePatternFlag ?. length > 0
75
+ ? ArrayPrototypeMap (
76
+ testNamePatternFlag ,
77
+ ( re ) => convertStringToRegExp ( re , '--test-name-pattern' )
78
+ )
79
+ : null
64
80
const kShouldAbort = Symbol ( 'kShouldAbort' )
65
81
const kRunHook = Symbol ( 'kRunHook' )
66
82
const kHookNames = ObjectSeal ( [ 'before' , 'after' , 'beforeEach' , 'afterEach' ] )
@@ -196,6 +212,18 @@ class Test extends AsyncResource {
196
212
this . timeout = timeout
197
213
}
198
214
215
+ if ( testNamePatterns !== null ) {
216
+ // eslint-disable-next-line no-use-before-define
217
+ const match = this instanceof TestHook || ArrayPrototypeSome (
218
+ testNamePatterns ,
219
+ ( re ) => RegExpPrototypeExec ( re , name ) !== null
220
+ )
221
+
222
+ if ( ! match ) {
223
+ skip = 'test name does not match pattern'
224
+ }
225
+ }
226
+
199
227
if ( testOnlyFlag && ! this . only ) {
200
228
skip = '\'only\' option not set'
201
229
}
@@ -673,6 +701,7 @@ class ItTest extends Test {
673
701
return { ctx : { signal : this . signal , name : this . name } , args : [ ] }
674
702
}
675
703
}
704
+
676
705
class Suite extends Test {
677
706
constructor ( options ) {
678
707
super ( options )
0 commit comments