Skip to content

Commit a9589d3

Browse files
committed
Move test location config into state
1 parent e7b34ce commit a9589d3

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

packages/jest-circus/src/event_handler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const TEST_TIMEOUT_SYMBOL = Symbol.for('TEST_TIMEOUT_SYMBOL');
2222

2323
const handler: EventHandler = (event, state): void => {
2424
switch (event.name) {
25+
case 'include_test_location_in_result': {
26+
state.includeTestLocationInResult = true;
27+
break;
28+
}
2529
case 'hook_start': {
2630
break;
2731
}

packages/jest-circus/src/legacy_code_todo_rewrite/jest_adapter_init.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ export const initialize = ({
7676
});
7777
}
7878

79+
if (config.testLocationInResults) {
80+
dispatch({
81+
name: 'include_test_location_in_result',
82+
});
83+
}
84+
7985
// Jest tests snapshotSerializers in order preceding built-in serializers.
8086
// Therefore, add in reverse because the last added is the first tested.
8187
config.snapshotSerializers
@@ -102,7 +108,7 @@ export const runAndTransformResultsToJestFormat = async ({
102108
globalConfig: GlobalConfig,
103109
testPath: string,
104110
}): Promise<TestResult> => {
105-
const runResult = await run(config);
111+
const runResult = await run();
106112

107113
let numFailingTests = 0;
108114
let numPassingTests = 0;

packages/jest-circus/src/run.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* @flow strict-local
88
*/
99

10-
import type {ProjectConfig} from 'types/Config';
11-
1210
import type {
1311
RunResult,
1412
TestEntry,
@@ -30,15 +28,14 @@ import {
3028

3129
const Promise = getOriginalPromise();
3230

33-
const run = async (config: ProjectConfig): Promise<RunResult> => {
31+
const run = async (): Promise<RunResult> => {
3432
const {rootDescribeBlock} = getState();
3533
dispatch({name: 'run_start'});
3634
await _runTestsForDescribeBlock(rootDescribeBlock);
3735
dispatch({name: 'run_finish'});
3836
return makeRunResult(
3937
getState().rootDescribeBlock,
4038
getState().unhandledErrors,
41-
config,
4239
);
4340
};
4441

packages/jest-circus/src/state.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const INITIAL_STATE: State = {
2626
currentDescribeBlock: ROOT_DESCRIBE_BLOCK,
2727
expand: undefined,
2828
hasFocusedTests: false, // whether .only has been used on any test/describe
29+
includeTestLocationInResult: false,
2930
rootDescribeBlock: ROOT_DESCRIBE_BLOCK,
3031
testNamePattern: null,
3132
testTimeout: 5000,

packages/jest-circus/src/utils.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* @flow strict-local
88
*/
99

10-
import type {ProjectConfig} from 'types/Config';
1110
import type {
1211
AsyncFn,
1312
BlockMode,
@@ -29,6 +28,8 @@ import StackUtils from 'stack-utils';
2928

3029
import prettyFormat from 'pretty-format';
3130

31+
import {getState} from './state';
32+
3233
// Try getting the real promise object from the context, if available. Someone
3334
// could have overridden it in a test. Async functions return it implicitly.
3435
// eslint-disable-next-line no-unused-vars
@@ -227,15 +228,15 @@ export const getTestDuration = (test: TestEntry): ?number => {
227228
export const makeRunResult = (
228229
describeBlock: DescribeBlock,
229230
unhandledErrors: Array<Error>,
230-
config: ProjectConfig,
231231
): RunResult => {
232232
return {
233-
testResults: makeTestResults(describeBlock, config),
233+
testResults: makeTestResults(describeBlock),
234234
unhandledErrors: unhandledErrors.map(_formatError),
235235
};
236236
};
237237

238238
const makeTestResults = (describeBlock: DescribeBlock, config): TestResults => {
239+
const {includeTestLocationInResult} = getState();
239240
let testResults = [];
240241
for (const test of describeBlock.tests) {
241242
const testPath = [];
@@ -251,7 +252,7 @@ const makeTestResults = (describeBlock: DescribeBlock, config): TestResults => {
251252
}
252253

253254
let location = null;
254-
if (config.testLocationInResults) {
255+
if (includeTestLocationInResult) {
255256
const stackLine = test.asyncError.stack.split('\n')[1];
256257
const {line, column} = stackUtils.parseLine(stackLine);
257258
location = {column, line};

types/Circus.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export type Hook = {
3232
export type EventHandler = (event: Event, state: State) => void;
3333

3434
export type Event =
35+
| {|
36+
name: 'include_test_location_in_result',
37+
|}
3538
| {|
3639
asyncError: Exception,
3740
mode: BlockMode,
@@ -156,6 +159,7 @@ export type State = {|
156159
testNamePattern: ?RegExp,
157160
expand?: boolean, // expand error messages
158161
unhandledErrors: Array<Exception>,
162+
includeTestLocationInResult: boolean,
159163
|};
160164

161165
export type DescribeBlock = {|

0 commit comments

Comments
 (0)