77
88import * as path from 'path' ;
99import type { Circus } from '@jest/types' ;
10- import { convertDescriptorToString , formatTime } from 'jest-util' ;
10+ import { ErrorWithStack , convertDescriptorToString , formatTime } from 'jest-util' ;
1111import isGeneratorFn from 'is-generator-fn' ;
1212import co from 'co' ;
1313import dedent = require( 'dedent' ) ;
@@ -43,7 +43,7 @@ export const makeDescribe = (
4343} ;
4444
4545export const makeTest = (
46- fn : Circus . TestFn | undefined ,
46+ fn : Circus . TestFn ,
4747 mode : Circus . TestMode ,
4848 name : Circus . TestName ,
4949 parent : Circus . DescribeBlock ,
@@ -159,17 +159,18 @@ function checkIsError(error: unknown): error is Error {
159159}
160160
161161export const callAsyncCircusFn = (
162- fn : Circus . AsyncFn ,
162+ testOrHook : Circus . TestEntry | Circus . Hook ,
163163 testContext : Circus . TestContext | undefined ,
164- asyncError : Circus . Exception ,
165- { isHook, timeout} : { isHook ?: boolean | null ; timeout : number } ,
164+ { isHook, timeout} : { isHook : boolean ; timeout : number } ,
166165) : Promise < unknown > => {
167166 let timeoutID : NodeJS . Timeout ;
168167 let completed = false ;
169168
169+ const { fn, asyncError} = testOrHook ;
170+
170171 return new Promise ( ( resolve , reject ) => {
171172 timeoutID = setTimeout (
172- ( ) => reject ( _makeTimeoutMessage ( timeout , ! ! isHook ) ) ,
173+ ( ) => reject ( _makeTimeoutMessage ( timeout , isHook ) ) ,
173174 timeout ,
174175 ) ;
175176
@@ -179,7 +180,7 @@ export const callAsyncCircusFn = (
179180 let returnedValue : unknown = undefined ;
180181 const done = ( reason ?: Error | string ) : void => {
181182 // We need to keep a stack here before the promise tick
182- const errorAtDone = new Error ( ) ;
183+ const errorAtDone = new ErrorWithStack ( undefined , done ) ;
183184 // Use `Promise.resolve` to allow the event loop to go a single tick in case `done` is called synchronously
184185 Promise . resolve ( ) . then ( ( ) => {
185186 if ( returnedValue !== undefined ) {
0 commit comments