CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jest-circus

The next-gen flux-based test runner for Jest that provides test framework globals and event-driven test execution

82

1.90x
Overview
Eval results
Files

test-execution.mddocs/

Test Execution

Core test execution engine that runs tests and produces results. This module provides the main entry point for executing test suites and handling test lifecycle management.

Capabilities

Run Function

Main test execution function that processes the test suite and returns results.

/**
 * Execute all tests in the current test suite
 * @returns Promise resolving to test execution results
 */
function run(): Promise<RunResult>;

interface RunResult {
  /** Array of unhandled errors that occurred during execution */
  unhandledErrors: Array<FormattedError>;
  /** Array of individual test results */
  testResults: Array<TestResult>;
}

interface TestResult {
  /** Test duration in milliseconds */
  duration?: number | null;
  /** Error messages if test failed */
  errors: Array<FormattedError>;
  /** Detailed error information */
  errorsDetailed: Array<unknown>;
  /** Number of times test was invoked */
  invocations: number;
  /** Test status */
  status: 'skip' | 'done' | 'todo';
  /** Location information */
  location?: {column: number; line: number} | null;
  /** Number of passing assertions */
  numPassingAsserts: number;
  /** Retry error reasons */
  retryReasons: Array<FormattedError>;
  /** Path of test names from root describe to test */
  testPath: Array<string>;
}

type FormattedError = string;

Usage Examples:

import { run } from "jest-circus";

// Execute all tests
const results = await run();

const passedTests = results.testResults.filter(t => t.status === 'done' && t.errors.length === 0);
const failedTests = results.testResults.filter(t => t.errors.length > 0);
const skippedTests = results.testResults.filter(t => t.status === 'skip');

console.log(`Tests passed: ${passedTests.length}`);
console.log(`Tests failed: ${failedTests.length}`);
console.log(`Tests skipped: ${skippedTests.length}`);

if (results.unhandledErrors.length > 0) {
  console.error("Unhandled errors:", results.unhandledErrors);
}

// Process individual test results
results.testResults.forEach(testResult => {
  if (testResult.errors.length > 0) {
    console.error(`Failed: ${testResult.testPath.join(' > ')}`);
    console.error(testResult.errors.join('\n'));
  }
});

Jest Adapter Integration

Jest adapter for integrating circus with Jest's test runner infrastructure.

/**
 * Jest test runner adapter function
 * @param globalConfig - Jest global configuration
 * @param config - Project-specific configuration
 * @param environment - Test environment instance
 * @param runtime - Jest runtime instance
 * @param testPath - Path to the test file
 * @param sendMessageToJest - Optional message handler
 * @returns Promise resolving to test results
 */
function jestAdapter(
  globalConfig: GlobalConfig,
  config: ProjectConfig,
  environment: JestEnvironment,
  runtime: Runtime,
  testPath: string,
  sendMessageToJest?: TestFileEvent
): Promise<TestResult>;

interface GlobalConfig {
  /** Maximum number of concurrent workers */
  maxWorkers: number;
  /** Whether to run tests in watch mode */
  watch: boolean;
  /** Whether to run tests in watch all mode */
  watchAll: boolean;
  /** Test timeout in milliseconds */
  testTimeout: number;
  /** Other global configuration options */
  [key: string]: any;
}

interface ProjectConfig {
  /** Test runner to use */
  testRunner: string;
  /** Test environment */
  testEnvironment: string;
  /** Setup files to run after environment setup */
  setupFilesAfterEnv: Array<string>;
  /** Whether to reset modules between tests */
  resetModules: boolean;
  /** Whether to clear mocks between tests */
  clearMocks: boolean;
  /** Whether to reset mocks between tests */
  resetMocks: boolean;
  /** Whether to restore mocks between tests */
  restoreMocks: boolean;
  /** Fake timers configuration */
  fakeTimers: {
    enableGlobally: boolean;
    legacyFakeTimers: boolean;
  };
  /** Other project configuration options */
  [key: string]: any;
}

interface TestResult {
  /** Test execution results */
  testResults: Array<AssertionResult>;
  /** Coverage information if collected */
  coverage?: any;
  /** Performance timing information */
  perfStats: {
    start: number;
    end: number;
    runtime: number;
    slow: boolean;
  };
  /** Snapshot data */
  snapshot: {
    added: number;
    fileDeleted: boolean;
    matched: number;
    unchecked: number;
    uncheckedKeys: Array<string>;
    unmatched: number;
    updated: number;
  };
  /** Source maps for coverage */
  sourceMaps?: any;
  /** Whether test execution was skipped */
  skipped: boolean;
  /** Other test result data */
  [key: string]: any;
}

Usage Examples:

// The Jest adapter is typically used internally by Jest
// when configured as the test runner:

// jest.config.js
module.exports = {
  testRunner: 'jest-circus/runner'
};

// Or via CLI:
// jest --testRunner='jest-circus/runner'

// The adapter can also be used programmatically:
import jestAdapter from 'jest-circus/runner';

const result = await jestAdapter(
  globalConfig,
  projectConfig, 
  environment,
  runtime,
  '/path/to/test.js'
);

Runner Configuration

Configuration options for customizing test execution behavior.

interface RunnerConfig {
  /** Maximum number of tests to run concurrently */
  maxConcurrency?: number;
  /** Default test timeout in milliseconds */
  testTimeout?: number;
  /** Random seed for test shuffling */
  seed?: number;
  /** Whether to randomize test order */
  randomize?: boolean;
  /** Pattern to match test names */
  testNamePattern?: string | RegExp;
  /** Whether to include test location in results */
  includeTestLocationInResult?: boolean;
}

Usage Examples:

import { setState, getState } from "jest-circus";

// Configure test execution
const currentState = getState();
setState({
  ...currentState,
  maxConcurrency: 5,      // Run up to 5 tests concurrently
  testTimeout: 10000,     // 10 second default timeout
  seed: 12345,            // Fixed seed for reproducible test order
  testNamePattern: /api/, // Only run tests matching "api"
  includeTestLocationInResult: true
});

Install with Tessl CLI

npx tessl i tessl/npm-jest-circus

docs

event-system.md

index.md

state-management.md

test-execution.md

test-globals.md

tile.json