Core functionality for Jest testing framework providing programmatic APIs for test discovery, scheduling, and CLI integration.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Test execution coordination system providing reporter management, test scheduling, and result aggregation. The TestScheduler handles parallel execution, result reporting, and error handling for Jest test runs.
Factory function for creating configured TestScheduler instances with reporter setup.
/**
* Creates and initializes a TestScheduler with reporters setup
* @param globalConfig - Jest global configuration
* @param context - Combined reporter and test runner context
* @returns Promise resolving to configured TestScheduler instance
*/
export async function createTestScheduler(
globalConfig: Config.GlobalConfig,
context: TestSchedulerContext
): Promise<TestScheduler>;Usage Example:
import { createTestScheduler } from "@jest/core";
import { Config } from "@jest/types";
// Setup configuration and context
const globalConfig: Config.GlobalConfig = {
maxWorkers: 4,
verbose: true,
coverage: false,
// ... other global config options
};
const context: TestSchedulerContext = {
// Reporter context
// Test runner context
// ... context properties
};
// Create scheduler with automatic reporter setup
const scheduler = await createTestScheduler(globalConfig, context);Core class managing test execution, reporters, and result aggregation. TestScheduler instances are created exclusively through the createTestScheduler factory function and cannot be instantiated directly.
/**
* Manages test execution scheduling and reporting
* Note: TestScheduler is not directly exported - use createTestScheduler() to obtain instances
*/
interface TestScheduler {
addReporter(reporter: Reporter): void;
removeReporter(reporterConstructor: ReporterConstructor): void;
scheduleTests(tests: Array<Test>, watcher: TestWatcher): Promise<AggregatedResult>;
}Add and remove reporters from the test execution pipeline.
/**
* Adds a reporter to the test execution pipeline
* @param reporter - Reporter instance to add
*/
addReporter(reporter: Reporter): void;
/**
* Removes a reporter from the execution pipeline
* @param reporterConstructor - Constructor of the reporter to remove
*/
removeReporter(reporterConstructor: ReporterConstructor): void;Usage Example:
import { DefaultReporter, VerboseReporter } from "@jest/reporters";
// Add reporters
const defaultReporter = new DefaultReporter(globalConfig, {}, context);
scheduler.addReporter(defaultReporter);
const verboseReporter = new VerboseReporter(globalConfig, {}, context);
scheduler.addReporter(verboseReporter);
// Remove a reporter
scheduler.removeReporter(VerboseReporter);Schedule and execute a collection of tests with comprehensive result reporting.
/**
* Schedules and executes a collection of tests
* @param tests - Array of test files to execute
* @param watcher - Test watcher for handling interruptions and watch mode
* @returns Promise resolving to aggregated test results
*/
async scheduleTests(
tests: Array<Test>,
watcher: TestWatcher
): Promise<AggregatedResult>;Usage Example:
import { TestWatcher } from "jest-watcher";
// Prepare tests (from SearchSource)
const tests: Array<Test> = [
{
context: testContext,
path: "/src/__tests__/example.test.js",
duration: undefined,
},
// ... more tests
];
// Create test watcher
const watcher = new TestWatcher({ isWatchMode: false });
// Schedule and execute tests
const results = await scheduler.scheduleTests(tests, watcher);
console.log(`Total tests: ${results.numTotalTests}`);
console.log(`Passed: ${results.numPassedTests}`);
console.log(`Failed: ${results.numFailedTests}`);
console.log(`Success: ${results.success}`);import { BaseReporter } from "@jest/reporters";
import type { AggregatedResult, Test, TestResult } from "@jest/test-result";
class CustomReporter extends BaseReporter {
onRunStart(aggregatedResult: AggregatedResult): void {
console.log("Test run started");
}
onTestFileStart(test: Test): void {
console.log(`Starting test: ${test.path}`);
}
onTestFileResult(test: Test, testResult: TestResult): void {
console.log(`Finished test: ${test.path}, passed: ${testResult.numPassingTests}`);
}
onRunComplete(aggregatedResult: AggregatedResult): void {
console.log("Test run completed");
}
}
// Add custom reporter
const customReporter = new CustomReporter(globalConfig, {}, context);
scheduler.addReporter(customReporter);const results = await scheduler.scheduleTests(tests, watcher);
// Check for failures
if (!results.success) {
console.error(`${results.numFailedTests} tests failed`);
// Examine individual test results
results.testResults.forEach(testResult => {
if (testResult.numFailingTests > 0) {
console.log(`Failed test file: ${testResult.testFilePath}`);
testResult.testResults.forEach(assertionResult => {
if (assertionResult.status === 'failed') {
console.log(` Failed test: ${assertionResult.fullName}`);
console.log(` Error: ${assertionResult.failureMessages[0]}`);
}
});
}
});
}
// Check for open handles
if (results.openHandles && results.openHandles.length > 0) {
console.warn(`${results.openHandles.length} open handles detected`);
}type TestSchedulerContext = ReporterContext & TestRunnerContext;
type ReporterConstructor = new (
globalConfig: Config.GlobalConfig,
reporterConfig: Record<string, unknown>,
reporterContext: ReporterContext
) => JestReporter;
interface AggregatedResult {
/** Number of failed individual tests */
numFailedTests: number;
/** Number of failed test suites */
numFailedTestSuites: number;
/** Number of passed individual tests */
numPassedTests: number;
/** Number of passed test suites */
numPassedTestSuites: number;
/** Number of pending individual tests */
numPendingTests: number;
/** Number of pending test suites */
numPendingTestSuites: number;
/** Number of test suites with runtime errors */
numRuntimeErrorTestSuites: number;
/** Total number of individual tests */
numTotalTests: number;
/** Total number of test suites */
numTotalTestSuites: number;
/** Array of open handles that may prevent Jest from exiting */
openHandles: Array<Error>;
/** Snapshot test summary */
snapshot: SnapshotSummary;
/** Test run start time */
startTime: number;
/** Whether the test run was successful */
success: boolean;
/** Array of individual test file results */
testResults: Array<TestResult>;
/** Whether the test run was interrupted */
wasInterrupted: boolean;
}
interface SnapshotSummary {
added: number;
didUpdate: boolean;
failure: boolean;
filesAdded: number;
filesRemoved: number;
filesRemovedList: Array<string>;
filesUnmatched: number;
filesUpdated: number;
matched: number;
total: number;
unchecked: number;
uncheckedKeysByFile: Array<{
filePath: string;
keys: Array<string>;
}>;
unmatched: number;
updated: number;
}