Core functionality for Jest testing framework providing programmatic APIs for test discovery, scheduling, and CLI integration.
npx @tessl/cli install tessl/npm-jest--core@30.0.0Jest Core provides the foundational functionality for Jest, a comprehensive JavaScript testing framework. It offers programmatic APIs for test discovery, test scheduling, and CLI integration, enabling developers to build custom testing workflows and integrate Jest into build tools and IDEs.
npm install @jest/coreimport { SearchSource, createTestScheduler, runCLI, getVersion } from "@jest/core";For CommonJS:
const { SearchSource, createTestScheduler, runCLI, getVersion } = require("@jest/core");import { runCLI } from "@jest/core";
import { Config } from "@jest/types";
// Run Jest programmatically with CLI-like interface
const argv: Config.Argv = {
// Jest CLI arguments
testMatch: ["**/__tests__/**/*.test.js"],
coverage: true,
verbose: true,
};
const projects = ["./my-project"];
const { results, globalConfig } = await runCLI(argv, projects);
console.log(`Tests: ${results.numTotalTests}, Failures: ${results.numFailedTests}`);Jest Core is built around several key components:
SearchSource class handles finding and filtering test files based on patterns and configurationsTestScheduler manages test execution coordination, reporter management, and result aggregationrunCLI function provides command-line interface compatibility for programmatic usage@jest/types Config interfacesCore functionality for finding and filtering test files based on patterns, changed files, and dependencies. Essential for watch mode, selective test running, and IDE integration.
export default class SearchSource {
constructor(context: TestContext);
isTestFilePath(path: string): boolean;
findMatchingTests(testPathPatternsExecutor: TestPathPatternsExecutor): SearchResult;
async findRelatedTests(allPaths: Set<string>, collectCoverage: boolean): Promise<SearchResult>;
findTestsByPaths(paths: Array<string>): SearchResult;
}
export type SearchResult = {
noSCM?: boolean;
stats?: Stats;
collectCoverageFrom?: Set<string>;
tests: Array<Test>;
total?: number;
};Test execution coordination system providing reporter management, test scheduling, and result aggregation. Handles parallel execution, result reporting, and error handling.
export async function createTestScheduler(
globalConfig: Config.GlobalConfig,
context: TestSchedulerContext
): Promise<TestScheduler>;Programmatic interface to Jest's command-line functionality, supporting all CLI options and returning structured results. Perfect for build tools, CI systems, and custom test runners.
export async function runCLI(
argv: Config.Argv,
projects: Array<string>
): Promise<{
results: AggregatedResult;
globalConfig: Config.GlobalConfig;
}>;Helper functions for version information and other utilities.
export default function getVersion(): string;interface TestContext {
config: Config.ProjectConfig;
hasteFS: IHasteFS;
moduleMap: IModuleMap;
resolver: IResolver;
}
interface Test {
context: TestContext;
duration?: number;
path: string;
}
interface AggregatedResult {
numFailedTests: number;
numFailedTestSuites: number;
numPassedTests: number;
numPassedTestSuites: number;
numPendingTests: number;
numPendingTestSuites: number;
numRuntimeErrorTestSuites: number;
numTotalTests: number;
numTotalTestSuites: number;
openHandles: Array<Error>;
snapshot: SnapshotSummary;
startTime: number;
success: boolean;
testResults: Array<TestResult>;
wasInterrupted: boolean;
}
interface Stats {
roots: number;
testMatch: number;
testPathIgnorePatterns: number;
testRegex: number;
testPathPatterns?: number;
}
type TestSchedulerContext = ReporterContext & TestRunnerContext;
type ReporterConstructor = new (
globalConfig: Config.GlobalConfig,
reporterConfig: Record<string, unknown>,
reporterContext: ReporterContext
) => JestReporter;
type Filter = (testPaths: Array<string>) => Promise<{
filtered: Array<string>;
}>;
interface TestScheduler {
addReporter(reporter: Reporter): void;
removeReporter(reporterConstructor: ReporterConstructor): void;
scheduleTests(tests: Array<Test>, watcher: TestWatcher): Promise<AggregatedResult>;
}