Comprehensive TypeScript type definitions for the Jest testing framework ecosystem providing shared types for configuration, test results, transforms, and global utilities.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Complete configuration types for Jest setup including fake timers, coverage, module resolution, and test execution options. Essential for creating type-safe Jest configurations and custom Jest tooling.
Types from external packages used in Jest configuration.
/**
* Report options from istanbul-reports package
*/
type ReportOptions = Record<string, any>;
/**
* Foreground color type from chalk package
*/
type ForegroundColor = string;
/**
* Test path patterns from @jest/pattern package
*/
type TestPathPatterns = Array<string>;
/**
* Snapshot format configuration from @jest/schemas package
*/
type SnapshotFormat = Record<string, any>;
/**
* Arguments type from yargs package
*/
type Arguments<T> = T & {
_: Array<string | number>;
$0: string;
};Main Jest configuration interface with all available options.
/**
* Initial Jest configuration options (re-exported from @jest/schemas)
*/
interface InitialOptions {
// Test execution
testEnvironment?: string;
testMatch?: Array<string>;
testRegex?: string | Array<string>;
testPathIgnorePatterns?: Array<string>;
testTimeout?: number;
// Coverage configuration
collectCoverage?: boolean;
collectCoverageFrom?: Array<string>;
coverageDirectory?: string;
coveragePathIgnorePatterns?: Array<string>;
coverageProvider?: CoverageProvider;
coverageReporters?: CoverageReporters;
coverageThreshold?: CoverageThreshold;
// Module configuration
moduleDirectories?: Array<string>;
moduleFileExtensions?: Array<string>;
moduleNameMapper?: Record<string, string | Array<string>>;
modulePathIgnorePatterns?: Array<string>;
modulePaths?: Array<string>;
// Transform configuration
transform?: Record<string, string | [string, Record<string, unknown>]>;
transformIgnorePatterns?: Array<string>;
// Fake timers
fakeTimers?: FakeTimers;
// Setup and teardown
setupFiles?: Array<string>;
setupFilesAfterEnv?: Array<string>;
globalSetup?: string;
globalTeardown?: string;
// Mocking
automock?: boolean;
clearMocks?: boolean;
resetMocks?: boolean;
restoreMocks?: boolean;
// Miscellaneous
bail?: boolean | number;
cache?: boolean;
cacheDirectory?: string;
maxWorkers?: number | string;
verbose?: boolean;
silent?: boolean;
// Jest-specific
roots?: Array<string>;
testRunner?: string;
testSequencer?: string;
}Comprehensive fake timers configuration types for controlling Jest's timer mocking.
/**
* APIs that can be faked by Jest's fake timers
*/
type FakeableAPI =
| 'Date'
| 'hrtime'
| 'nextTick'
| 'performance'
| 'queueMicrotask'
| 'requestAnimationFrame'
| 'cancelAnimationFrame'
| 'requestIdleCallback'
| 'cancelIdleCallback'
| 'setImmediate'
| 'clearImmediate'
| 'setInterval'
| 'clearInterval'
| 'setTimeout'
| 'clearTimeout';
/**
* Global fake timers configuration
*/
type GlobalFakeTimersConfig = {
/**
* Whether fake timers should be enabled globally for all test files
* @defaultValue false
*/
enableGlobally?: boolean;
};
/**
* Modern fake timers configuration
*/
type FakeTimersConfig = {
/**
* If set to true, all timers will be advanced automatically by 20ms every 20ms.
* A custom time delta may be provided by passing a number.
* @defaultValue false
*/
advanceTimers?: boolean | number;
/**
* List of APIs that should not be faked
* @defaultValue []
*/
doNotFake?: Array<FakeableAPI>;
/**
* Sets current system time to be used by fake timers, in milliseconds
* @defaultValue Date.now()
*/
now?: number | Date;
/**
* Maximum number of recursive timers when calling jest.runAllTimers()
* @defaultValue 100_000
*/
timerLimit?: number;
/**
* Use old fake timers implementation instead of @sinonjs/fake-timers
* @defaultValue false
*/
legacyFakeTimers?: false;
};
/**
* Legacy fake timers configuration
*/
type LegacyFakeTimersConfig = {
/**
* Use old fake timers implementation
* @defaultValue false
*/
legacyFakeTimers?: true;
};
/**
* Combined fake timers configuration
*/
type FakeTimers = GlobalFakeTimersConfig &
(
| (FakeTimersConfig & {
now?: Exclude<FakeTimersConfig['now'], Date>;
})
| LegacyFakeTimersConfig
);Types for Jest's code coverage configuration and reporting.
/**
* Coverage provider options
*/
type CoverageProvider = 'babel' | 'v8';
/**
* Coverage reporter names
*/
type CoverageReporterName = keyof ReportOptions;
/**
* Coverage reporter with options
*/
type CoverageReporterWithOptions<K = CoverageReporterName> =
K extends CoverageReporterName
? ReportOptions[K] extends never
? never
: [K, Partial<ReportOptions[K]>]
: never;
/**
* Array of coverage reporters
*/
type CoverageReporters = Array<CoverageReporterName | CoverageReporterWithOptions>;
/**
* Coverage threshold values
*/
type CoverageThresholdValue = {
branches?: number;
functions?: number;
lines?: number;
statements?: number;
};
/**
* Coverage threshold configuration by file pattern
*/
type CoverageThreshold = {
[path: string]: CoverageThresholdValue;
global: CoverageThresholdValue;
};Types for Jest's Haste module system and module resolution.
/**
* Haste module system configuration
*/
type HasteConfig = {
/** Whether to hash files using SHA-1 */
computeSha1?: boolean;
/** The platform to use as default, e.g. 'ios' */
defaultPlatform?: string | null;
/** Force use of Node's fs APIs rather than shelling out to find */
forceNodeFilesystemAPI?: boolean;
/**
* Whether to follow symlinks when crawling for files.
* Cannot be used in projects with watchman set to true.
*/
enableSymlinks?: boolean;
/** String to a custom implementation of Haste */
hasteImplModulePath?: string;
/** All platforms to target, e.g ['ios', 'android'] */
platforms?: Array<string>;
/** Whether to throw an error on module collision */
throwOnModuleCollision?: boolean;
/** Custom HasteMap module */
hasteMapModulePath?: string;
/** Whether to retain all files, allowing e.g. search for tests in node_modules */
retainAllFiles?: boolean;
};Additional configuration-related types and interfaces.
/**
* Reporter configuration tuple
*/
type ReporterConfig = [string, Record<string, unknown>];
/**
* Transformer configuration tuple
*/
type TransformerConfig = [string, Record<string, unknown>];
/**
* Global variables configuration
*/
interface ConfigGlobals {
[K: string]: unknown;
}
/**
* Display name configuration for projects
*/
type DisplayName = {
name: string;
color: typeof ForegroundColor;
};
/**
* Snapshot update state options
*/
type SnapshotUpdateState = 'all' | 'new' | 'none';
/**
* Notification mode options
*/
type NotifyMode =
| 'always'
| 'failure'
| 'success'
| 'change'
| 'success-change'
| 'failure-change';
/**
* Test sharding configuration
*/
type ShardConfig = {
shardIndex: number;
shardCount: number;
};Configuration interfaces used during Jest execution.
/**
* Global configuration for Jest execution
*/
interface GlobalConfig {
bail: number;
changedSince?: string;
changedFilesWithAncestor: boolean;
ci: boolean;
collectCoverage: boolean;
collectCoverageFrom: Array<string>;
coverageDirectory: string;
coveragePathIgnorePatterns?: Array<string>;
coverageProvider: CoverageProvider;
coverageReporters: CoverageReporters;
coverageThreshold?: CoverageThreshold;
detectLeaks: boolean;
detectOpenHandles: boolean;
expand: boolean;
filter?: string;
findRelatedTests: boolean;
forceExit: boolean;
json: boolean;
globalSetup?: string;
globalTeardown?: string;
lastCommit: boolean;
logHeapUsage: boolean;
listTests: boolean;
maxConcurrency: number;
maxWorkers: number;
noStackTrace: boolean;
nonFlagArgs: Array<string>;
noSCM?: boolean;
notify: boolean;
notifyMode: NotifyMode;
outputFile?: string;
onlyChanged: boolean;
onlyFailures: boolean;
openHandlesTimeout: number;
passWithNoTests: boolean;
projects: Array<string>;
randomize?: boolean;
replname?: string;
reporters?: Array<ReporterConfig>;
runInBand: boolean;
runTestsByPath: boolean;
rootDir: string;
seed: number;
showSeed?: boolean;
shard?: ShardConfig;
silent?: boolean;
skipFilter: boolean;
snapshotFormat: SnapshotFormat;
errorOnDeprecated: boolean;
testFailureExitCode: number;
testNamePattern?: string;
testPathPatterns: TestPathPatterns;
testResultsProcessor?: string;
testSequencer: string;
testTimeout?: number;
updateSnapshot: SnapshotUpdateState;
useStderr: boolean;
verbose?: boolean;
waitForUnhandledRejections: boolean;
watch: boolean;
watchAll: boolean;
watchman: boolean;
watchPlugins?: Array<{
path: string;
config: Record<string, unknown>;
}> | null;
workerIdleMemoryLimit?: number;
workerThreads?: boolean;
}
/**
* Project-specific configuration
*/
interface ProjectConfig {
automock: boolean;
cache: boolean;
cacheDirectory: string;
clearMocks: boolean;
collectCoverageFrom: Array<string>;
coverageDirectory: string;
coveragePathIgnorePatterns: Array<string>;
coverageReporters: CoverageReporters;
cwd: string;
dependencyExtractor?: string;
detectLeaks: boolean;
detectOpenHandles: boolean;
displayName?: DisplayName;
errorOnDeprecated: boolean;
extensionsToTreatAsEsm: Array<string>;
fakeTimers: FakeTimers;
filter?: string;
forceCoverageMatch: Array<string>;
globalSetup?: string;
globalTeardown?: string;
globals: ConfigGlobals;
haste: HasteConfig;
id: string;
injectGlobals: boolean;
moduleDirectories: Array<string>;
moduleFileExtensions: Array<string>;
moduleNameMapper: Array<[string, string]>;
modulePathIgnorePatterns: Array<string>;
modulePaths?: Array<string>;
openHandlesTimeout: number;
preset?: string;
prettierPath: string;
reporters: Array<string | ReporterConfig>;
resetMocks: boolean;
resetModules: boolean;
resolver?: string;
restoreMocks: boolean;
rootDir: string;
roots: Array<string>;
runner: string;
runtime?: string;
sandboxInjectedGlobals: Array<keyof typeof globalThis>;
setupFiles: Array<string>;
setupFilesAfterEnv: Array<string>;
skipFilter: boolean;
skipNodeResolution?: boolean;
slowTestThreshold: number;
snapshotResolver?: string;
snapshotSerializers: Array<string>;
snapshotFormat: SnapshotFormat;
testEnvironment: string;
testEnvironmentOptions: Record<string, unknown>;
testMatch: Array<string>;
testLocationInResults: boolean;
testPathIgnorePatterns: Array<string>;
testRegex: Array<string | RegExp>;
testRunner: string;
testTimeout: number;
transform: Array<[string, string, Record<string, unknown>]>;
transformIgnorePatterns: Array<string>;
watchPathIgnorePatterns: Array<string>;
unmockedModulePathPatterns?: Array<string>;
waitForUnhandledRejections: boolean;
workerIdleMemoryLimit?: number;
}Comprehensive type for Jest CLI arguments.
/**
* Jest CLI arguments type
*/
type Argv = Arguments<
Partial<{
all: boolean;
automock: boolean;
bail: boolean | number;
cache: boolean;
cacheDirectory: string;
changedFilesWithAncestor: boolean;
changedSince: string;
ci: boolean;
clearCache: boolean;
clearMocks: boolean;
collectCoverage: boolean;
collectCoverageFrom: string;
color: boolean;
colors: boolean;
config: string;
coverage: boolean;
coverageDirectory: string;
coveragePathIgnorePatterns: Array<string>;
coverageReporters: Array<string>;
coverageThreshold: string;
debug: boolean;
env: string;
expand: boolean;
findRelatedTests: boolean;
forceExit: boolean;
globals: string;
globalSetup: string | null | undefined;
globalTeardown: string | null | undefined;
haste: string;
ignoreProjects: Array<string>;
injectGlobals: boolean;
json: boolean;
lastCommit: boolean;
logHeapUsage: boolean;
maxWorkers: number | string;
moduleDirectories: Array<string>;
moduleFileExtensions: Array<string>;
moduleNameMapper: string;
modulePathIgnorePatterns: Array<string>;
modulePaths: Array<string>;
noStackTrace: boolean;
notify: boolean;
notifyMode: string;
onlyChanged: boolean;
onlyFailures: boolean;
outputFile: string;
preset: string | null | undefined;
prettierPath: string | null | undefined;
projects: Array<string>;
randomize: boolean;
reporters: Array<string>;
resetMocks: boolean;
resetModules: boolean;
resolver: string | null | undefined;
restoreMocks: boolean;
rootDir: string;
roots: Array<string>;
runInBand: boolean;
seed: number;
showSeed: boolean;
selectProjects: Array<string>;
setupFiles: Array<string>;
setupFilesAfterEnv: Array<string>;
shard: string;
showConfig: boolean;
silent: boolean;
snapshotSerializers: Array<string>;
testEnvironment: string;
testEnvironmentOptions: string;
testFailureExitCode: string | null | undefined;
testMatch: string | Array<string>;
testNamePattern: string;
testPathIgnorePatterns: Array<string>;
testPathPatterns: Array<string>;
testRegex: string | Array<string>;
testResultsProcessor: string;
testRunner: string;
testSequencer: string;
testTimeout: number | null | undefined;
transform: string;
transformIgnorePatterns: Array<string>;
unmockedModulePathPatterns: Array<string> | null | undefined;
updateSnapshot: boolean;
useStderr: boolean;
verbose: boolean;
version: boolean;
watch: boolean;
watchAll: boolean;
watchman: boolean;
watchPathIgnorePatterns: Array<string>;
workerIdleMemoryLimit: number | string;
workerThreads: boolean;
}>
>;Usage Examples:
import type { Config } from "@jest/types";
// Basic Jest configuration
const jestConfig: Config.InitialOptions = {
testEnvironment: "node",
collectCoverage: true,
coverageDirectory: "coverage",
coverageReporters: ["text", "lcov", "html"],
testMatch: ["**/__tests__/**/*.test.ts"],
transform: {
"^.+\\.ts$": "ts-jest",
},
};
// Fake timers configuration
const timerConfig: Config.FakeTimersConfig = {
enableGlobally: true,
advanceTimers: true,
doNotFake: ["performance", "Date"],
timerLimit: 50000,
};
// Coverage threshold configuration
const coverageThreshold: Config.CoverageThreshold = {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
"./src/utils/": {
branches: 90,
functions: 90,
},
};