Delightful JavaScript testing framework with built-in test runner, assertion library, mocking, and coverage reporting.
npx @tessl/cli install tessl/npm-jest@30.1.0Jest is a comprehensive JavaScript testing framework designed for delightful testing experiences. It provides a complete testing solution that works out of the box for most JavaScript projects, featuring instant feedback through intelligent watch mode, powerful snapshot testing, extensive mocking capabilities, built-in code coverage reporting, and seamless integration with modern JavaScript tooling including Babel, TypeScript, webpack, and various bundlers.
npm install jestimport { runCLI, createTestScheduler, SearchSource, getVersion, run, buildArgv } from "jest";
import type { Config } from "jest";For CommonJS:
const { runCLI, createTestScheduler, SearchSource, getVersion, run, buildArgv } = require("jest");Jest can be used programmatically or via CLI:
import { runCLI } from "jest";
// Run Jest programmatically
const { results, globalConfig } = await runCLI(
{ roots: ["<rootDir>/src"], testMatch: ["**/__tests__/**/*.test.js"] },
["./src"]
);
console.log(`Tests completed: ${results.numTotalTests}`);
console.log(`Tests passed: ${results.numPassedTests}`);CLI usage:
# Run all tests
jest
# Run tests in watch mode
jest --watch
# Run with coverage
jest --coverage
# Run specific test files
jest user.test.jsJest is built around several key components:
Core test running functionality including programmatic API and CLI runner with comprehensive test discovery and execution capabilities.
function runCLI(
argv: Config.Argv,
projects: Array<string>
): Promise<{
results: AggregatedResult;
globalConfig: Config.GlobalConfig;
}>;
function run(maybeArgv?: Array<string>, project?: string): Promise<void>;Command-line interface providing over 70 options for test execution, coverage collection, watch mode, output formatting, and project configuration.
function buildArgv(maybeArgv?: Array<string>): Promise<Config.Argv>;Advanced test file discovery system with pattern matching, dependency tracking, and change detection for optimized test runs.
class SearchSource {
constructor(context: TestContext);
isTestFilePath(path: string): boolean;
findMatchingTests(testPathPatternsExecutor: TestPathPatternsExecutor): SearchResult;
findTestsByPaths(paths: Array<string>): SearchResult;
findRelatedTests(allPaths: Set<string>, collectCoverage: boolean): Promise<SearchResult>;
}Comprehensive configuration system supporting global settings, per-project configuration, and extensive customization options for all aspects of test execution.
interface Config {
// Main configuration interface (alias for Config.InitialOptions)
testEnvironment?: string;
testMatch?: Array<string>;
transform?: Record<string, string>;
setupFilesAfterEnv?: Array<string>;
moduleNameMapping?: Record<string, string>;
collectCoverage?: boolean;
}
interface Config.GlobalConfig {
bail: number;
collectCoverage: boolean;
maxWorkers: number;
rootDir: string;
watch: boolean;
watchAll: boolean;
}Test execution scheduling with multi-process coordination, reporter management, and comprehensive result aggregation.
function createTestScheduler(
globalConfig: Config.GlobalConfig,
context: TestSchedulerContext
): Promise<TestScheduler>;
class TestScheduler {
constructor(globalConfig: Config.GlobalConfig, context: TestSchedulerContext);
addReporter(reporter: Reporter): void;
scheduleTests(tests: Array<Test>, watcher: TestWatcher): Promise<AggregatedResult>;
}function getVersion(): string;Returns the current Jest version.
interface AggregatedResult {
numTotalTests: number;
numPassedTests: number;
numFailedTests: number;
numPendingTests: number;
numRuntimeErrorTestSuites: number;
numTotalTestSuites: number;
numPassedTestSuites: number;
numFailedTestSuites: number;
numPendingTestSuites: number;
openHandles: Array<Error>;
snapshot: SnapshotSummary;
success: boolean;
startTime: number;
testResults: Array<TestResult>;
wasInterrupted: boolean;
}
interface SearchResult {
noSCM?: boolean;
stats?: Stats;
collectCoverageFrom?: Set<string>;
tests: Array<Test>;
total?: number;
}
interface TestContext {
config: Config.ProjectConfig;
hasteFS: IHasteFS;
moduleMap: IModuleMap;
resolver: IResolver;
}
interface TestSchedulerContext extends ReporterContext, TestRunnerContext {}
interface Test {
context: TestContext;
duration?: number;
path: string;
}