@@ -40,6 +40,7 @@ export class Vitest {
40
40
41
41
invalidates : Set < string > = new Set ( )
42
42
changedTests : Set < string > = new Set ( )
43
+ filenamePattern ?: string
43
44
runningPromise ?: Promise < void >
44
45
closingPromise ?: Promise < void >
45
46
@@ -372,15 +373,21 @@ export class Vitest {
372
373
}
373
374
374
375
async changeNamePattern ( pattern : string , files : string [ ] = this . state . getFilepaths ( ) , trigger ?: string ) {
376
+ // Empty test name pattern should reset filename pattern as well
377
+ if ( pattern === '' )
378
+ this . filenamePattern = undefined
379
+
375
380
this . config . testNamePattern = pattern ? new RegExp ( pattern ) : undefined
376
381
await this . rerunFiles ( files , trigger )
377
382
}
378
383
379
384
async changeFilenamePattern ( pattern : string ) {
385
+ this . filenamePattern = pattern
386
+
380
387
const files = this . state . getFilepaths ( )
381
- if ( ! pattern )
388
+ if ( ! this . filenamePattern )
382
389
return await this . rerunFiles ( files , 'reset filename pattern' )
383
- const filteredFiles = await this . globTestFiles ( [ pattern ] )
390
+ const filteredFiles = await this . globTestFiles ( [ this . filenamePattern ] )
384
391
await this . rerunFiles ( filteredFiles , 'change filename pattern' )
385
392
}
386
393
@@ -433,7 +440,17 @@ export class Vitest {
433
440
this . isFirstRun = false
434
441
435
442
this . snapshot . clear ( )
436
- const files = Array . from ( this . changedTests )
443
+ let files = Array . from ( this . changedTests )
444
+
445
+ if ( this . filenamePattern ) {
446
+ const filteredFiles = await this . globTestFiles ( [ this . filenamePattern ] )
447
+ files = files . filter ( file => filteredFiles . includes ( file ) )
448
+
449
+ // A file that does not match the current filename pattern was changed
450
+ if ( files . length === 0 )
451
+ return
452
+ }
453
+
437
454
this . changedTests . clear ( )
438
455
439
456
if ( this . coverageProvider && this . config . coverage . cleanOnRerun )
0 commit comments