@@ -99,6 +99,7 @@ export class Vitest {
9999 /** @internal */ filenamePattern ?: string [ ]
100100 /** @internal */ runningPromise ?: Promise < TestRunResult >
101101 /** @internal */ closingPromise ?: Promise < void >
102+ /** @internal */ cancelPromise ?: Promise < void | void [ ] >
102103 /** @internal */ isCancelling = false
103104 /** @internal */ coreWorkspaceProject : TestProject | undefined
104105 /** @internal */ _browserSessions = new BrowserSessions ( )
@@ -705,6 +706,7 @@ export class Vitest {
705706 await this . _testRun . start ( specs )
706707
707708 // previous run
709+ await this . cancelPromise
708710 await this . runningPromise
709711 this . _onCancelListeners . clear ( )
710712 this . isCancelling = false
@@ -806,6 +808,7 @@ export class Vitest {
806808 this . state . collectPaths ( filepaths )
807809
808810 // previous run
811+ await this . cancelPromise
809812 await this . runningPromise
810813 this . _onCancelListeners . clear ( )
811814 this . isCancelling = false
@@ -859,7 +862,9 @@ export class Vitest {
859862 */
860863 async cancelCurrentRun ( reason : CancelReason ) : Promise < void > {
861864 this . isCancelling = true
862- await Promise . all ( [ ...this . _onCancelListeners ] . map ( listener => listener ( reason ) ) )
865+ this . cancelPromise = Promise . all ( [ ...this . _onCancelListeners ] . map ( listener => listener ( reason ) ) )
866+
867+ await this . cancelPromise . finally ( ( ) => ( this . cancelPromise = undefined ) )
863868 await this . runningPromise
864869 }
865870
@@ -1045,6 +1050,7 @@ export class Vitest {
10451050 private async scheduleRerun ( triggerId : string ) : Promise < void > {
10461051 const currentCount = this . restartsCount
10471052 clearTimeout ( this . _rerunTimer )
1053+ await this . cancelPromise
10481054 await this . runningPromise
10491055 clearTimeout ( this . _rerunTimer )
10501056
0 commit comments