The next-gen flux-based test runner for Jest that provides test framework globals and event-driven test execution
82
Low-level state management for controlling test execution state and accessing runtime information. The state system provides centralized tracking of test execution progress, errors, and configuration.
Functions for getting, setting, and resetting the global circus state.
/**
* Get the current circus state
* @returns Current state object
*/
function getState(): State;
/**
* Set the circus state
* @param state - New state object
* @returns The state that was set
*/
function setState(state: State): State;
/**
* Reset state to initial values
*/
function resetState(): void;Usage Examples:
import { getState, setState, resetState } from "jest-circus";
// Get current state
const currentState = getState();
console.log("Current test:", currentState.currentlyRunningTest);
console.log("Has focused tests:", currentState.hasFocusedTests);
// Modify state (advanced usage)
const state = getState();
const modifiedState = {
...state,
testTimeout: 10000, // Set 10 second timeout
maxConcurrency: 10 // Allow 10 concurrent tests
};
setState(modifiedState);
// Reset to initial state
resetState();Note: The event dispatching functions (dispatch, dispatchSync, addEventHandler) are internal to jest-circus and not part of the public API. They are used internally by the framework and test environments. For custom event handling, see the Event System documentation which covers how test environments can handle events via the handleTestEvent method.
interface State {
/** Currently executing describe block */
currentDescribeBlock: DescribeBlock;
/** Currently running test, null if none */
currentlyRunningTest?: TestEntry | null;
/** Root describe block containing all tests */
rootDescribeBlock: DescribeBlock;
/** Whether test execution has started */
hasStarted: boolean;
/** Whether any tests have .only modifier */
hasFocusedTests: boolean;
/** Whether to include test location in results */
includeTestLocationInResult: boolean;
/** Maximum number of concurrent tests */
maxConcurrency: number;
/** Parent process reference */
parentProcess: NodeJS.Process | null;
/** Random seed for test shuffling */
seed: number;
/** Pattern to match test names */
testNamePattern?: RegExp | null;
/** Default timeout for tests in milliseconds */
testTimeout: number;
/** Array of unhandled errors */
unhandledErrors: Array<Exception>;
/** Whether to expand snapshots */
expand?: boolean;
/** Whether to randomize test order */
randomize?: boolean;
}
interface DescribeBlock {
type: 'describeBlock';
children: Array<DescribeBlock | TestEntry>;
name: BlockName;
parent?: DescribeBlock;
mode: BlockMode;
hooks: Array<Hook>;
}
interface TestEntry {
type: 'test';
asyncError: Exception;
concurrent: boolean;
errors: Array<Exception>;
retryReasons: Array<Exception>;
fn: TestFn;
mode: TestMode;
name: TestName;
parent: DescribeBlock;
seenDone: boolean;
timeout?: number;
failing: boolean;
invocations: number;
numPassingAsserts: number;
startedAt?: number | null;
duration?: number | null;
status?: 'skip' | 'done' | 'todo' | null;
}
interface Hook {
asyncError: Error;
fn: HookFn;
type: HookType;
parent: DescribeBlock;
seenDone: boolean;
timeout: number | undefined | null;
}
type HookType = 'beforeAll' | 'afterAll' | 'beforeEach' | 'afterEach';
type Exception = any;
type BlockName = string;
type TestName = string;The state management system uses internal symbols and globals to maintain test state across the execution lifecycle. These internal mechanisms are not part of the public API and should not be accessed directly. Use the provided getState(), setState(), and resetState() functions to interact with the test state.
Install with Tessl CLI
npx tessl i tessl/npm-jest-circusevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10