From f65ed9e0efdcd17af5ec5b1f72ca04bae9e0e7ae Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 27 May 2018 11:50:15 +0200 Subject: [PATCH] [WIP] try to fix circus as well --- packages/jest-circus/src/run.js | 22 +++++++++++----------- packages/jest-circus/src/utils.js | 2 +- packages/jest-cli/src/get_node_handles.js | 3 +++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/jest-circus/src/run.js b/packages/jest-circus/src/run.js index b929757c43de..50ac39ef5c1c 100644 --- a/packages/jest-circus/src/run.js +++ b/packages/jest-circus/src/run.js @@ -17,7 +17,7 @@ import type { import {getState, dispatch} from './state'; import { - callAsyncFn, + callAsyncCircusFn, getAllHooksForDescribe, getEachHooksForTest, getTestID, @@ -44,7 +44,7 @@ const _runTestsForDescribeBlock = async (describeBlock: DescribeBlock) => { const {beforeAll, afterAll} = getAllHooksForDescribe(describeBlock); for (const hook of beforeAll) { - await _callHook({describeBlock, hook}); + await _callCircusHook({describeBlock, hook}); } for (const test of describeBlock.tests) { await _runTest(test); @@ -55,7 +55,7 @@ const _runTestsForDescribeBlock = async (describeBlock: DescribeBlock) => { } for (const hook of afterAll) { - await _callHook({describeBlock, hook}); + await _callCircusHook({describeBlock, hook}); } dispatch({describeBlock, name: 'run_describe_finish'}); }; @@ -83,13 +83,13 @@ const _runTest = async (test: TestEntry): Promise => { // hooks after that. break; } - await _callHook({hook, test, testContext}); + await _callCircusHook({hook, test, testContext}); } - await _callTest(test, testContext); + await _callCircusTest(test, testContext); for (const hook of afterEach) { - await _callHook({hook, test, testContext}); + await _callCircusHook({hook, test, testContext}); } // `afterAll` hooks should not affect test status (pass or fail), because if @@ -98,7 +98,7 @@ const _runTest = async (test: TestEntry): Promise => { dispatch({name: 'test_done', test}); }; -const _callHook = ({ +const _callCircusHook = ({ hook, test, describeBlock, @@ -111,14 +111,14 @@ const _callHook = ({ }): Promise => { dispatch({hook, name: 'hook_start'}); const timeout = hook.timeout || getState().testTimeout; - return callAsyncFn(hook.fn, testContext, {isHook: true, timeout}) + return callAsyncCircusFn(hook.fn, testContext, {isHook: true, timeout}) .then(() => dispatch({describeBlock, hook, name: 'hook_success', test})) .catch(error => dispatch({describeBlock, error, hook, name: 'hook_failure', test}), ); }; -const _callTest = async ( +const _callCircusTest = ( test: TestEntry, testContext: TestContext, ): Promise => { @@ -128,10 +128,10 @@ const _callTest = async ( if (test.errors.length) { // We don't run the test if there's already an error in before hooks. - return; + return Promise.resolve(); } - await callAsyncFn(test.fn, testContext, {isHook: false, timeout}) + return callAsyncCircusFn(test.fn, testContext, {isHook: false, timeout}) .then(() => dispatch({name: 'test_fn_success', test})) .catch(error => dispatch({error, name: 'test_fn_failure', test})); }; diff --git a/packages/jest-circus/src/utils.js b/packages/jest-circus/src/utils.js index 2890801b84c1..d16134351493 100644 --- a/packages/jest-circus/src/utils.js +++ b/packages/jest-circus/src/utils.js @@ -140,7 +140,7 @@ const _makeTimeoutMessage = (timeout, isHook) => // the original values in the variables before we require any files. const {setTimeout, clearTimeout} = global; -export const callAsyncFn = ( +export const callAsyncCircusFn = ( fn: AsyncFn, testContext: ?TestContext, { diff --git a/packages/jest-cli/src/get_node_handles.js b/packages/jest-cli/src/get_node_handles.js index bf84fc39f937..e4154e34a6e9 100644 --- a/packages/jest-cli/src/get_node_handles.js +++ b/packages/jest-cli/src/get_node_handles.js @@ -25,6 +25,9 @@ export default function collectHandles(): () => Array { if ( error.stack.includes('Runtime.requireModule') || + (error.stack.includes('callAsyncCircusFn') && + (error.stack.includes('_callCircusTest') || + error.stack.includes('_callCircusHook'))) || error.stack.includes('asyncJestTest') || error.stack.includes('asyncJestLifecycle') ) {