Skip to content

Commit

Permalink
Add useful APIs to jest-circus.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed May 29, 2021
1 parent 7109b8c commit c05521f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
3 changes: 3 additions & 0 deletions packages/jest-circus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 20 additions & 14 deletions packages/jest-circus/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,28 @@ const eventHandlers: Array<Circus.EventHandler> = [

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 =>
Expand Down

0 comments on commit c05521f

Please sign in to comment.