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
22
33'use strict'
44
55const {
6+ ArrayPrototypeMap,
67 ArrayPrototypePush,
78 ArrayPrototypeReduce,
89 ArrayPrototypeShift,
910 ArrayPrototypeSlice,
11+ ArrayPrototypeSome,
1012 ArrayPrototypeUnshift,
1113 FunctionPrototype,
1214 MathMax,
@@ -15,6 +17,7 @@ const {
1517 PromisePrototypeThen,
1618 PromiseResolve,
1719 ReflectApply,
20+ RegExpPrototypeExec,
1821 SafeMap,
1922 SafeSet,
2023 SafePromiseAll,
@@ -33,7 +36,11 @@ const {
3336} = require ( '#internal/errors' )
3437const { getOptionValue } = require ( '#internal/options' )
3538const { 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' )
3744const {
3845 createDeferredPromise,
3946 kEmptyObject
@@ -61,6 +68,15 @@ const kDefaultTimeout = null
6168const noop = FunctionPrototype
6269const isTestRunner = getOptionValue ( '--test' )
6370const 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
6480const kShouldAbort = Symbol ( 'kShouldAbort' )
6581const kRunHook = Symbol ( 'kRunHook' )
6682const kHookNames = ObjectSeal ( [ 'before' , 'after' , 'beforeEach' , 'afterEach' ] )
@@ -196,6 +212,18 @@ class Test extends AsyncResource {
196212 this . timeout = timeout
197213 }
198214
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+
199227 if ( testOnlyFlag && ! this . only ) {
200228 skip = '\'only\' option not set'
201229 }
@@ -673,6 +701,7 @@ class ItTest extends Test {
673701 return { ctx : { signal : this . signal , name : this . name } , args : [ ] }
674702 }
675703}
704+
676705class Suite extends Test {
677706 constructor ( options ) {
678707 super ( options )
0 commit comments