Skip to content

Commit c05521f

Browse files
committed
Add useful APIs to jest-circus.
1 parent 7109b8c commit c05521f

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

packages/jest-circus/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import {bind as bindEach} from 'jest-each';
1010
import {ErrorWithStack, isPromise} from 'jest-util';
1111
import {dispatchSync} from './state';
1212

13+
export {setState, getState, resetState} from './state';
14+
export {default as run} from './run';
15+
1316
type THook = (fn: Circus.HookFn, timeout?: number) => void;
1417
type DescribeFn = (
1518
blockName: Circus.BlockName,

packages/jest-circus/src/state.ts

+20-14
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,28 @@ const eventHandlers: Array<Circus.EventHandler> = [
1818

1919
export const ROOT_DESCRIBE_BLOCK_NAME = 'ROOT_DESCRIBE_BLOCK';
2020

21-
const ROOT_DESCRIBE_BLOCK = makeDescribe(ROOT_DESCRIBE_BLOCK_NAME);
22-
const INITIAL_STATE: Circus.State = {
23-
currentDescribeBlock: ROOT_DESCRIBE_BLOCK,
24-
currentlyRunningTest: null,
25-
expand: undefined,
26-
hasFocusedTests: false,
27-
hasStarted: false,
28-
includeTestLocationInResult: false,
29-
parentProcess: null,
30-
rootDescribeBlock: ROOT_DESCRIBE_BLOCK,
31-
testNamePattern: null,
32-
testTimeout: 5000,
33-
unhandledErrors: [],
21+
const createState = (): Circus.State => {
22+
const ROOT_DESCRIBE_BLOCK = makeDescribe(ROOT_DESCRIBE_BLOCK_NAME);
23+
return {
24+
currentDescribeBlock: ROOT_DESCRIBE_BLOCK,
25+
currentlyRunningTest: null,
26+
expand: undefined,
27+
hasFocusedTests: false,
28+
hasStarted: false,
29+
includeTestLocationInResult: false,
30+
parentProcess: null,
31+
rootDescribeBlock: ROOT_DESCRIBE_BLOCK,
32+
testNamePattern: null,
33+
testTimeout: 5000,
34+
unhandledErrors: [],
35+
};
3436
};
3537

36-
global[STATE_SYM] = INITIAL_STATE;
38+
export const resetState = (): void => {
39+
global[STATE_SYM] = createState();
40+
};
41+
42+
resetState();
3743

3844
export const getState = (): Circus.State => global[STATE_SYM];
3945
export const setState = (state: Circus.State): Circus.State =>

0 commit comments

Comments
 (0)