File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -375,6 +375,14 @@ This methods overrides the global [test name pattern](/config/#testnamepattern).
375
375
This method doesn ' t start running any tests. To run tests with updated pattern, call [`runTestSpecifications`](#runtestspecifications).
376
376
:::
377
377
378
+ ## getGlobalTestNamePattern
379
+
380
+ ` ` ` ts
381
+ function getGlobalTestNamePattern(): RegExp | undefined
382
+ ` ` `
383
+
384
+ Returns the regexp used for the global test name pattern .
385
+
378
386
## resetGlobalTestNamePattern
379
387
380
388
` ` ` ts
Original file line number Diff line number Diff line change @@ -1001,6 +1001,16 @@ export class Vitest {
1001
1001
}
1002
1002
}
1003
1003
1004
+ /**
1005
+ * Returns the regexp used for the global test name pattern.
1006
+ */
1007
+ public getGlobalTestNamePattern ( ) : RegExp | undefined {
1008
+ if ( this . configOverride . testNamePattern != null ) {
1009
+ return this . configOverride . testNamePattern
1010
+ }
1011
+ return this . config . testNamePattern
1012
+ }
1013
+
1004
1014
/**
1005
1015
* Resets the global test name pattern. This method doesn't run any tests.
1006
1016
*/
Original file line number Diff line number Diff line change @@ -94,3 +94,22 @@ it.each([
94
94
} )
95
95
} )
96
96
} )
97
+
98
+ it ( 'can modify the global test name pattern' , async ( ) => {
99
+ const { ctx } = await runVitest ( {
100
+ testNamePattern : 'custom' ,
101
+ include : [ 'non-existing' ] ,
102
+ } )
103
+
104
+ expect ( ctx ?. getGlobalTestNamePattern ( ) ) . toEqual ( / c u s t o m / )
105
+
106
+ // reset just removes the override, user config is not touched
107
+ ctx ?. resetGlobalTestNamePattern ( )
108
+ expect ( ctx ?. getGlobalTestNamePattern ( ) ) . toEqual ( / c u s t o m / )
109
+
110
+ ctx ?. setGlobalTestNamePattern ( / n e w p a t t e r n / )
111
+ expect ( ctx ?. getGlobalTestNamePattern ( ) ) . toEqual ( / n e w p a t t e r n / )
112
+
113
+ ctx ?. resetGlobalTestNamePattern ( )
114
+ expect ( ctx ?. getGlobalTestNamePattern ( ) ) . toEqual ( / c u s t o m / )
115
+ } )
You can’t perform that action at this time.
0 commit comments