@@ -23,9 +23,17 @@ import "./global-setup.js";
23
23
} ;
24
24
}
25
25
26
- export default async function ( { test, updateSnapshot, port } ) {
26
+ export default async function ( {
27
+ test,
28
+ updateSnapshot,
29
+ testNamePattern,
30
+ port,
31
+ } ) {
27
32
port . postMessage ( "start" ) ;
28
33
34
+ const testNamePatternRE =
35
+ testNamePattern != null ? new RegExp ( testNamePattern , "i" ) : null ;
36
+
29
37
/** @type {Stats } */
30
38
const stats = { passes : 0 , failures : 0 , pending : 0 , start : 0 , end : 0 } ;
31
39
/** @type {Array<InternalTestResult> } */
@@ -40,7 +48,7 @@ export default async function ({ test, updateSnapshot, port }) {
40
48
expect . setState ( { snapshotState } ) ;
41
49
42
50
stats . start = performance . now ( ) ;
43
- await runTestBlock ( tests , hasFocusedTests , results , stats ) ;
51
+ await runTestBlock ( tests , hasFocusedTests , testNamePatternRE , results , stats ) ;
44
52
stats . end = performance . now ( ) ;
45
53
46
54
snapshotState . _inlineSnapshots . forEach ( ( { frame } ) => {
@@ -63,6 +71,7 @@ async function loadTests(testFile) {
63
71
async function runTestBlock (
64
72
block ,
65
73
hasFocusedTests ,
74
+ testNamePatternRE ,
66
75
results ,
67
76
stats ,
68
77
ancestors = [ ]
@@ -75,12 +84,20 @@ async function runTestBlock(
75
84
76
85
if (
77
86
mode === "skip" ||
78
- ( hasFocusedTests && type === "test" && mode !== "only" )
87
+ ( hasFocusedTests && type === "test" && mode !== "only" ) ||
88
+ shouldSkip ( testNamePatternRE , getFullName ( nextAncestors ) )
79
89
) {
80
90
stats . pending ++ ;
81
91
results . push ( { ancestors, title : name , errors : [ ] , skipped : true } ) ;
82
92
} else if ( type === "describeBlock" ) {
83
- await runTestBlock ( child , hasFocusedTests , results , stats , nextAncestors ) ;
93
+ await runTestBlock (
94
+ child ,
95
+ hasFocusedTests ,
96
+ testNamePatternRE ,
97
+ results ,
98
+ stats ,
99
+ nextAncestors
100
+ ) ;
84
101
} else if ( type === "test" ) {
85
102
await runHooks ( "beforeEach" , block , results , stats , nextAncestors , true ) ;
86
103
await runTest ( fn , stats , results , ancestors , name ) ;
@@ -93,6 +110,17 @@ async function runTestBlock(
93
110
return results ;
94
111
}
95
112
113
+ function shouldSkip ( testNamePatternRE , testName ) {
114
+ return testNamePatternRE && ! testNamePatternRE . test ( testName ) ;
115
+ }
116
+
117
+ /**
118
+ * @param {string[] } pieces
119
+ */
120
+ function getFullName ( pieces ) {
121
+ return pieces . join ( " " ) ;
122
+ }
123
+
96
124
/**
97
125
* @param {Function } fn
98
126
* @param {Stats } stats
@@ -103,7 +131,7 @@ async function runTestBlock(
103
131
async function runTest ( fn , stats , results , ancestors , name ) {
104
132
expect . setState ( {
105
133
suppressedErrors : [ ] ,
106
- currentTestName : ancestors . concat ( name ) . join ( " " ) ,
134
+ currentTestName : getFullName ( ancestors . concat ( name ) ) ,
107
135
} ) ;
108
136
109
137
const errors = [ ] ;
0 commit comments