Skip to content

Commit 860e923

Browse files
committed
[WIP] try to fix circus as well
1 parent e53d7d3 commit 860e923

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

packages/jest-circus/src/run.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717

1818
import {getState, dispatch} from './state';
1919
import {
20-
callAsyncFn,
20+
callAsyncCircusFn,
2121
getAllHooksForDescribe,
2222
getEachHooksForTest,
2323
getTestID,
@@ -44,7 +44,7 @@ const _runTestsForDescribeBlock = async (describeBlock: DescribeBlock) => {
4444
const {beforeAll, afterAll} = getAllHooksForDescribe(describeBlock);
4545

4646
for (const hook of beforeAll) {
47-
await _callHook({describeBlock, hook});
47+
await _callCircusHook({describeBlock, hook});
4848
}
4949

5050
// Tests that fail and are retried we run after other tests
@@ -77,7 +77,7 @@ const _runTestsForDescribeBlock = async (describeBlock: DescribeBlock) => {
7777
}
7878

7979
for (const hook of afterAll) {
80-
await _callHook({describeBlock, hook});
80+
await _callCircusHook({describeBlock, hook});
8181
}
8282
dispatch({describeBlock, name: 'run_describe_finish'});
8383
};
@@ -105,13 +105,13 @@ const _runTest = async (test: TestEntry): Promise<void> => {
105105
// hooks after that.
106106
break;
107107
}
108-
await _callHook({hook, test, testContext});
108+
await _callCircusHook({hook, test, testContext});
109109
}
110110

111-
await _callTest(test, testContext);
111+
await _callCircusTest(test, testContext);
112112

113113
for (const hook of afterEach) {
114-
await _callHook({hook, test, testContext});
114+
await _callCircusHook({hook, test, testContext});
115115
}
116116

117117
// `afterAll` hooks should not affect test status (pass or fail), because if
@@ -120,7 +120,7 @@ const _runTest = async (test: TestEntry): Promise<void> => {
120120
dispatch({name: 'test_done', test});
121121
};
122122

123-
const _callHook = ({
123+
const _callCircusHook = ({
124124
hook,
125125
test,
126126
describeBlock,
@@ -133,14 +133,14 @@ const _callHook = ({
133133
}): Promise<mixed> => {
134134
dispatch({hook, name: 'hook_start'});
135135
const timeout = hook.timeout || getState().testTimeout;
136-
return callAsyncFn(hook.fn, testContext, {isHook: true, timeout})
136+
return callAsyncCircusFn(hook.fn, testContext, {isHook: true, timeout})
137137
.then(() => dispatch({describeBlock, hook, name: 'hook_success', test}))
138138
.catch(error =>
139139
dispatch({describeBlock, error, hook, name: 'hook_failure', test}),
140140
);
141141
};
142142

143-
const _callTest = async (
143+
const _callCircusTest = (
144144
test: TestEntry,
145145
testContext: TestContext,
146146
): Promise<void> => {
@@ -150,10 +150,10 @@ const _callTest = async (
150150

151151
if (test.errors.length) {
152152
// We don't run the test if there's already an error in before hooks.
153-
return;
153+
return Promise.resolve();
154154
}
155155

156-
await callAsyncFn(test.fn, testContext, {isHook: false, timeout})
156+
return callAsyncCircusFn(test.fn, testContext, {isHook: false, timeout})
157157
.then(() => dispatch({name: 'test_fn_success', test}))
158158
.catch(error => dispatch({error, name: 'test_fn_failure', test}));
159159
};

packages/jest-circus/src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const _makeTimeoutMessage = (timeout, isHook) =>
164164
// the original values in the variables before we require any files.
165165
const {setTimeout, clearTimeout} = global;
166166

167-
export const callAsyncFn = (
167+
export const callAsyncCircusFn = (
168168
fn: AsyncFn,
169169
testContext: ?TestContext,
170170
{isHook, timeout}: {isHook?: ?boolean, timeout: number},

packages/jest-cli/src/collectHandles.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@ import type {ProjectConfig} from 'types/Config';
1111

1212
import {formatExecError} from 'jest-message-util';
1313

14+
function stackIsFromUser(stack) {
15+
// Either the test file, or something required by it
16+
if (stack.includes('Runtime.requireModule')) {
17+
return true;
18+
}
19+
20+
// jest-jasmine it or describe call
21+
if (stack.includes('asyncJestTest') || stack.includes('asyncJestLifecycle')) {
22+
return true;
23+
}
24+
25+
// An async function call from within circus
26+
if (stack.includes('callAsyncCircusFn')) {
27+
// jest-circus it or describe call
28+
return (
29+
stack.includes('_callCircusTest') || stack.includes('_callCircusHook')
30+
);
31+
}
32+
33+
return false;
34+
}
35+
1436
// Inspired by https://github.com/mafintosh/why-is-node-running/blob/master/index.js
1537
// Extracted as we want to format the result ourselves
1638
export default function collectHandles(): () => Array<Error> {
@@ -26,11 +48,7 @@ export default function collectHandles(): () => Array<Error> {
2648
Error.captureStackTrace(error, initHook);
2749
}
2850

29-
if (
30-
error.stack.includes('Runtime.requireModule') ||
31-
error.stack.includes('asyncJestTest') ||
32-
error.stack.includes('asyncJestLifecycle')
33-
) {
51+
if (stackIsFromUser(error.stack)) {
3452
activeHandles.set(asyncId, error);
3553
}
3654
}

0 commit comments

Comments
 (0)