| 76 | // We make *all* functions async and run `done` right away if they |
| 77 | // didn't return a promise. |
| 78 | const asyncJestLifecycle = function (done: DoneFn) { |
| 79 | const wrappedFn = isGeneratorFn(fn) ? co.wrap(fn) : fn; |
| 80 | const returnValue = wrappedFn.call({}, doneFnNoop); |
| 81 | |
| 82 | if (isPromise(returnValue)) { |
| 83 | returnValue.then(done.bind(null, null), (error: Error) => { |
| 84 | const {isError: checkIsError, message} = isError(error); |
| 85 | |
| 86 | if (message) { |
| 87 | extraError.message = message; |
| 88 | extraError.stack = |
| 89 | originalExtraErrorStack && |
| 90 | originalExtraErrorStack.replace('Error: ', `Error: ${message}`); |
| 91 | } |
| 92 | done.fail(checkIsError ? error : extraError); |
| 93 | }); |
| 94 | } else { |
| 95 | done(); |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | return originalFn.call(env, asyncJestLifecycle, timeout); |
| 100 | }; |