@@ -2,6 +2,7 @@ import type { CancelReason, File, TaskResultPack } from '@vitest/runner'
22import type { Writable } from 'node:stream'
33import type { ViteDevServer } from 'vite'
44import type { defineWorkspace } from 'vitest/config'
5+ import type { RunnerTask , RunnerTestSuite } from '../public'
56import type { SerializedCoverageConfig } from '../runtime/config'
67import type { ArgumentsType , OnServerRestartHandler , OnTestsRerunHandler , ProvidedContext , UserConsoleLog } from '../types/general'
78import type { ProcessPool , WorkspaceSpec } from './pool'
@@ -687,7 +688,11 @@ export class Vitest {
687688 await Promise . all ( this . projects . map ( p => p . _initBrowserServer ( ) ) )
688689 }
689690
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+
691696 if ( this . filenamePattern ) {
692697 const filteredFiles = await this . globTestFiles ( [ this . filenamePattern ] )
693698 files = files . filter ( file => filteredFiles . some ( f => f [ 1 ] === file ) )
@@ -702,11 +707,29 @@ export class Vitest {
702707 await this . report ( 'onWatcherStart' , this . state . getFiles ( files ) )
703708 }
704709
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+
705726 async changeProjectName ( pattern : string ) {
706727 if ( pattern === '' ) {
707728 delete this . configOverride . project
708729 }
709- else { this . configOverride . project = pattern }
730+ else {
731+ this . configOverride . project = pattern
732+ }
710733
711734 this . projects = this . resolvedProjects . filter ( p => p . getName ( ) === pattern )
712735 const files = ( await this . globTestSpecs ( ) ) . map ( spec => spec . moduleId )
0 commit comments