@@ -2,6 +2,7 @@ import type { CancelReason, File, TaskResultPack } from '@vitest/runner'
2
2
import type { Writable } from 'node:stream'
3
3
import type { ViteDevServer } from 'vite'
4
4
import type { defineWorkspace } from 'vitest/config'
5
+ import type { RunnerTask , RunnerTestSuite } from '../public'
5
6
import type { SerializedCoverageConfig } from '../runtime/config'
6
7
import type { ArgumentsType , OnServerRestartHandler , OnTestsRerunHandler , ProvidedContext , UserConsoleLog } from '../types/general'
7
8
import type { ProcessPool , WorkspaceSpec } from './pool'
@@ -687,7 +688,11 @@ export class Vitest {
687
688
await Promise . all ( this . projects . map ( p => p . _initBrowserServer ( ) ) )
688
689
}
689
690
690
- async rerunFiles ( files : string [ ] = this . state . getFilepaths ( ) , trigger ?: string , allTestsRun = true ) {
691
+ async rerunFiles ( files : string [ ] = this . state . getFilepaths ( ) , trigger ?: string , allTestsRun = true , resetTestNamePattern = false ) {
692
+ if ( resetTestNamePattern ) {
693
+ this . configOverride . testNamePattern = undefined
694
+ }
695
+
691
696
if ( this . filenamePattern ) {
692
697
const filteredFiles = await this . globTestFiles ( [ this . filenamePattern ] )
693
698
files = files . filter ( file => filteredFiles . some ( f => f [ 1 ] === file ) )
@@ -702,11 +707,29 @@ export class Vitest {
702
707
await this . report ( 'onWatcherStart' , this . state . getFiles ( files ) )
703
708
}
704
709
710
+ private isSuite ( task : RunnerTask ) : task is RunnerTestSuite {
711
+ return Object . hasOwnProperty . call ( task , 'tasks' )
712
+ }
713
+
714
+ async rerunTask ( id : string ) {
715
+ const task = this . state . idMap . get ( id )
716
+ if ( ! task ) {
717
+ throw new Error ( `Task ${ id } was not found` )
718
+ }
719
+ await this . changeNamePattern (
720
+ task . name ,
721
+ [ task . file . filepath ] ,
722
+ this . isSuite ( task ) ? 'rerun suite' : 'rerun test' ,
723
+ )
724
+ }
725
+
705
726
async changeProjectName ( pattern : string ) {
706
727
if ( pattern === '' ) {
707
728
delete this . configOverride . project
708
729
}
709
- else { this . configOverride . project = pattern }
730
+ else {
731
+ this . configOverride . project = pattern
732
+ }
710
733
711
734
this . projects = this . resolvedProjects . filter ( p => p . getName ( ) === pattern )
712
735
const files = ( await this . globTestSpecs ( ) ) . map ( spec => spec . moduleId )
0 commit comments