diff --git a/packages/jest-circus/src/index.ts b/packages/jest-circus/src/index.ts index ca212b3fd657..26052438c6e1 100644 --- a/packages/jest-circus/src/index.ts +++ b/packages/jest-circus/src/index.ts @@ -10,6 +10,9 @@ import {bind as bindEach} from 'jest-each'; import {ErrorWithStack, isPromise} from 'jest-util'; import {dispatchSync} from './state'; +export {setState, getState, resetState} from './state'; +export {default as run} from './run'; + type THook = (fn: Circus.HookFn, timeout?: number) => void; type DescribeFn = ( blockName: Circus.BlockName, diff --git a/packages/jest-circus/src/state.ts b/packages/jest-circus/src/state.ts index 5af3c07c22b0..6f208ab04fcf 100644 --- a/packages/jest-circus/src/state.ts +++ b/packages/jest-circus/src/state.ts @@ -18,22 +18,28 @@ const eventHandlers: Array = [ export const ROOT_DESCRIBE_BLOCK_NAME = 'ROOT_DESCRIBE_BLOCK'; -const ROOT_DESCRIBE_BLOCK = makeDescribe(ROOT_DESCRIBE_BLOCK_NAME); -const INITIAL_STATE: Circus.State = { - currentDescribeBlock: ROOT_DESCRIBE_BLOCK, - currentlyRunningTest: null, - expand: undefined, - hasFocusedTests: false, - hasStarted: false, - includeTestLocationInResult: false, - parentProcess: null, - rootDescribeBlock: ROOT_DESCRIBE_BLOCK, - testNamePattern: null, - testTimeout: 5000, - unhandledErrors: [], +const createState = (): Circus.State => { + const ROOT_DESCRIBE_BLOCK = makeDescribe(ROOT_DESCRIBE_BLOCK_NAME); + return { + currentDescribeBlock: ROOT_DESCRIBE_BLOCK, + currentlyRunningTest: null, + expand: undefined, + hasFocusedTests: false, + hasStarted: false, + includeTestLocationInResult: false, + parentProcess: null, + rootDescribeBlock: ROOT_DESCRIBE_BLOCK, + testNamePattern: null, + testTimeout: 5000, + unhandledErrors: [], + }; }; -global[STATE_SYM] = INITIAL_STATE; +export const resetState = (): void => { + global[STATE_SYM] = createState(); +}; + +resetState(); export const getState = (): Circus.State => global[STATE_SYM]; export const setState = (state: Circus.State): Circus.State =>