@@ -40,6 +40,7 @@ export class Vitest {
4040
4141 invalidates : Set < string > = new Set ( )
4242 changedTests : Set < string > = new Set ( )
43+ filenamePattern ?: string
4344 runningPromise ?: Promise < void >
4445 closingPromise ?: Promise < void >
4546
@@ -372,15 +373,21 @@ export class Vitest {
372373 }
373374
374375 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+
375380 this . config . testNamePattern = pattern ? new RegExp ( pattern ) : undefined
376381 await this . rerunFiles ( files , trigger )
377382 }
378383
379384 async changeFilenamePattern ( pattern : string ) {
385+ this . filenamePattern = pattern
386+
380387 const files = this . state . getFilepaths ( )
381- if ( ! pattern )
388+ if ( ! this . filenamePattern )
382389 return await this . rerunFiles ( files , 'reset filename pattern' )
383- const filteredFiles = await this . globTestFiles ( [ pattern ] )
390+ const filteredFiles = await this . globTestFiles ( [ this . filenamePattern ] )
384391 await this . rerunFiles ( filteredFiles , 'change filename pattern' )
385392 }
386393
@@ -433,7 +440,17 @@ export class Vitest {
433440 this . isFirstRun = false
434441
435442 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+
437454 this . changedTests . clear ( )
438455
439456 if ( this . coverageProvider && this . config . coverage . cleanOnRerun )
0 commit comments