@@ -271,12 +271,14 @@ async function callAroundHooks<THook extends Function>(
271271 timeout : number ,
272272 phase : 'setup' | 'teardown' ,
273273 stackTraceError : Error | undefined ,
274- ) : { promise : Promise < never > ; clear : ( ) => void } => {
274+ ) : { promise : Promise < never > ; isTimedOut : ( ) => boolean ; clear : ( ) => void } => {
275275 let timer : ReturnType < typeof setTimeout > | undefined
276+ let timedout = false
276277
277278 const promise = new Promise < never > ( ( _ , reject ) => {
278279 if ( timeout > 0 && timeout !== Number . POSITIVE_INFINITY ) {
279280 timer = setTimeout ( ( ) => {
281+ timedout = true
280282 const error = makeAroundHookTimeoutError ( hookName , phase , timeout , stackTraceError )
281283 onTimeout ?.( error )
282284 reject ( error )
@@ -292,7 +294,7 @@ async function callAroundHooks<THook extends Function>(
292294 }
293295 }
294296
295- return { promise, clear }
297+ return { promise, clear, isTimedOut : ( ) => timedout }
296298 }
297299
298300 const runNextHook = async ( index : number ) : Promise < void > => {
@@ -305,8 +307,8 @@ async function callAroundHooks<THook extends Function>(
305307 const stackTraceError = getAroundHookStackTrace ( hook )
306308
307309 let useCalled = false
308- let setupTimeout : { promise : Promise < never > ; clear : ( ) => void }
309- let teardownTimeout : { promise : Promise < never > ; clear : ( ) => void } | undefined
310+ let setupTimeout : ReturnType < typeof createTimeoutPromise >
311+ let teardownTimeout : ReturnType < typeof createTimeoutPromise > | undefined
310312
311313 // Promise that resolves when use() is called (setup phase complete)
312314 let resolveUseCalled ! : ( ) => void
@@ -329,6 +331,12 @@ async function callAroundHooks<THook extends Function>(
329331 } )
330332
331333 const use = async ( ) => {
334+ // shouldn't continue to next (e.g. runTest/Suite) when aroundEach/All setup timed out.
335+ if ( setupTimeout . isTimedOut ( ) ) {
336+ // we can throw any error to bail out since this is not seen by end users
337+ throw new Error ( '__VITEST_INTERNAL_AROUND_HOOK_ABORT__' )
338+ }
339+
332340 if ( useCalled ) {
333341 throw new AroundHookMultipleCallsError (
334342 `The \`${ callbackName } \` callback was called multiple times in the \`${ hookName } \` hook. `
0 commit comments