or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli-integration.mdindex.mdtest-discovery.mdtest-scheduling.md
tile.json

tessl/npm-jest--core

Core functionality for Jest testing framework providing programmatic APIs for test discovery, scheduling, and CLI integration.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@jest/core@30.0.x

To install, run

npx @tessl/cli install tessl/npm-jest--core@30.0.0

index.mddocs/

Jest Core

Jest 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.

Package Information

  • Package Name: @jest/core
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @jest/core

Core Imports

import { SearchSource, createTestScheduler, runCLI, getVersion } from "@jest/core";

For CommonJS:

const { SearchSource, createTestScheduler, runCLI, getVersion } = require("@jest/core");

Basic Usage

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}`);

Architecture

Jest Core is built around several key components:

  • Test Discovery: SearchSource class handles finding and filtering test files based on patterns and configurations
  • Test Scheduling: TestScheduler manages test execution coordination, reporter management, and result aggregation
  • CLI Integration: runCLI function provides command-line interface compatibility for programmatic usage
  • Configuration System: Deep integration with Jest's configuration system via @jest/types Config interfaces
  • Reporter System: Built-in support for multiple reporters and custom reporter registration

Capabilities

Test Discovery and Search

Core 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 Discovery

Test Scheduling and Execution

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>;

Test Scheduling

CLI Integration

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;
}>;

CLI Integration

Utility Functions

Helper functions for version information and other utilities.

export default function getVersion(): string;

Core Types

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>;
}