Skip to content

defineJestConfig

Defines a TypeScript project’s jest configuration.

The defaults: the tests are src/**\/*.test.ts, run in the node environment, transformed by ts-jest, as ESM when the package is (see DefineJestConfigOptions.esm); a .js relative import resolves onto its .ts source; coverage is v8 over src/, without the barrels, the declarations, the tests and the test helpers, reported as text, lcov and html into coverage/. Every jest option in options replaces its default, except moduleNameMapper, whose entries are added to the .js mapper.

Import:

import { defineJestConfig } from '@mnaoumov/typescript-dev-toolkit/test-runners/jest-config';

Signature:

function defineJestConfig(options: DefineJestConfigOptions): { filter?: string; id?: string; automock?: boolean; bail?: number | boolean; cache?: boolean; cacheDirectory?: string; ci?: boolean; clearMocks?: boolean; changedFilesWithAncestor?: boolean; changedSince?: string; collectCoverage?: boolean; collectCoverageFrom?: string[]; collectTests?: boolean; coverageDirectory?: string; coveragePathIgnorePatterns?: string[]; coverageProvider?: "babel" | "v8"; coverageReporters?: ("json" | "clover" | "cobertura" | "html-spa" | "html" | "json-summary" | "lcov" | "lcovonly" | "none" | "teamcity" | "text" | "text-lcov" | "text-summary" | ["json" | "clover" | "cobertura" | "html-spa" | "html" | "json-summary" | "lcov" | "lcovonly" | "none" | "teamcity" | "text" | "text-lcov" | "text-summary", { [x: string]: unknown; }])[]; coverageThreshold?: { [path: string]: { branches?: number | undefined; functions?: number | undefined; lines?: number | undefined; statements?: number | undefined; }; global: { branches?: number; functions?: number; lines?: number; statements?: number; }; }; dependencyExtractor?: string; detectLeaks?: boolean; detectOpenHandles?: boolean; displayName?: string | { name: string; color: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright"; }; expand?: boolean; extensionsToTreatAsEsm?: string[]; fakeTimers?: { enableGlobally?: boolean; } & ({ advanceTimers?: number | boolean; doNotFake?: ("Date" | "hrtime" | "nextTick" | "performance" | "queueMicrotask" | "requestAnimationFrame" | "cancelAnimationFrame" | "requestIdleCallback" | "cancelIdleCallback" | "setImmediate" | "clearImmediate" | "setInterval" | "clearInterval" | "setTimeout" | "clearTimeout" | "Temporal")[]; now?: number; timerLimit?: number; legacyFakeTimers?: false; } | { legacyFakeTimers?: true; }); findRelatedTests?: boolean; forceCoverageMatch?: string[]; forceExit?: boolean; json?: boolean; globals?: { [x: string]: unknown; }; globalSetup?: string | null; globalTeardown?: string | null; haste?: { computeSha1?: boolean; defaultPlatform?: string | null; forceNodeFilesystemAPI?: boolean; enableSymlinks?: boolean; hasteImplModulePath?: string; platforms?: string[]; throwOnModuleCollision?: boolean; hasteMapModulePath?: string; retainAllFiles?: boolean; }; injectGlobals?: boolean; reporters?: (string | [string, { [x: string]: unknown; }])[]; logHeapUsage?: boolean; lastCommit?: boolean; listTests?: boolean; maxConcurrency?: number; maxWorkers?: string | number; moduleDirectories?: string[]; moduleFileExtensions?: string[]; moduleNameMapper?: { [x: string]: string | string[]; }; modulePathIgnorePatterns?: string[]; modulePaths?: string[]; noStackTrace?: boolean; notify?: boolean; notifyMode?: string; onlyChanged?: boolean; onlyFailures?: boolean; openHandlesTimeout?: number; outputFile?: string; passWithNoTests?: boolean; preset?: string | null; prettierPath?: string | null; projects?: (string | { [x: string]: unknown; })[]; randomize?: boolean; replname?: string | null; resetMocks?: boolean; resetModules?: boolean; resolver?: string | null; restoreMocks?: boolean; rootDir?: string; roots?: string[]; runner?: string | [string, { [x: string]: unknown; }]; runTestsByPath?: boolean; runtime?: string; sandboxInjectedGlobals?: string[]; setupFiles?: string[]; setupFilesAfterEnv?: string[]; showSeed?: boolean; silent?: boolean; skipFilter?: boolean; skipNodeResolution?: boolean; slowTestThreshold?: number; snapshotResolver?: string; snapshotSerializers?: string[]; snapshotFormat?: { callToJSON?: boolean; compareKeys?: null; escapeRegex?: boolean; escapeString?: boolean; highlight?: boolean; indent?: number; maxDepth?: number; maxWidth?: number; min?: boolean; printBasicPrototype?: boolean; printFunctionName?: boolean; theme?: { comment?: string; content?: string; prop?: string; tag?: string; value?: string; }; }; errorOnDeprecated?: boolean; testEnvironment?: string; testEnvironmentOptions?: { [x: string]: unknown; }; testFailureExitCode?: number; testLocationInResults?: boolean; testMatch?: string | string[]; testNamePattern?: string; testPathIgnorePatterns?: string[]; testRegex?: string | string[]; testResultsProcessor?: string; testRunner?: string; testSequencer?: string; testTimeout?: number; transform?: { [x: string]: string | [string, unknown]; }; transformIgnorePatterns?: string[]; watchPathIgnorePatterns?: string[]; unmockedModulePathPatterns?: string[]; updateSnapshot?: boolean; useStderr?: boolean; verbose?: boolean; waitForUnhandledRejections?: boolean; watch?: boolean; watchAll?: boolean; watchman?: boolean; watchPlugins?: (string | [string, unknown])[]; workerIdleMemoryLimit?: string | number; workerThreads?: boolean; workerGracefulExitTimeout?: number; }

Parameters:

Parameter Type Description
options DefineJestConfigOptions The configuration options.

Returns: { filter?: string; id?: string; automock?: boolean; bail?: number | boolean; cache?: boolean; cacheDirectory?: string; ci?: boolean; clearMocks?: boolean; changedFilesWithAncestor?: boolean; changedSince?: string; collectCoverage?: boolean; collectCoverageFrom?: string[]; collectTests?: boolean; coverageDirectory?: string; coveragePathIgnorePatterns?: string[]; coverageProvider?: “babel” | “v8”; coverageReporters?: (“json” | “clover” | “cobertura” | “html-spa” | “html” | “json-summary” | “lcov” | “lcovonly” | “none” | “teamcity” | “text” | “text-lcov” | “text-summary” | [“json” | “clover” | “cobertura” | “html-spa” | “html” | “json-summary” | “lcov” | “lcovonly” | “none” | “teamcity” | “text” | “text-lcov” | “text-summary”, { [x: string]: unknown; }])[]; coverageThreshold?: { [path: string]: { branches?: number | undefined; functions?: number | undefined; lines?: number | undefined; statements?: number | undefined; }; global: { branches?: number; functions?: number; lines?: number; statements?: number; }; }; dependencyExtractor?: string; detectLeaks?: boolean; detectOpenHandles?: boolean; displayName?: string | { name: string; color: “black” | “red” | “green” | “yellow” | “blue” | “magenta” | “cyan” | “white” | “gray” | “grey” | “blackBright” | “redBright” | “greenBright” | “yellowBright” | “blueBright” | “magentaBright” | “cyanBright” | “whiteBright”; }; expand?: boolean; extensionsToTreatAsEsm?: string[]; fakeTimers?: { enableGlobally?: boolean; } & ({ advanceTimers?: number | boolean; doNotFake?: (“Date” | “hrtime” | “nextTick” | “performance” | “queueMicrotask” | “requestAnimationFrame” | “cancelAnimationFrame” | “requestIdleCallback” | “cancelIdleCallback” | “setImmediate” | “clearImmediate” | “setInterval” | “clearInterval” | “setTimeout” | “clearTimeout” | “Temporal”)[]; now?: number; timerLimit?: number; legacyFakeTimers?: false; } | { legacyFakeTimers?: true; }); findRelatedTests?: boolean; forceCoverageMatch?: string[]; forceExit?: boolean; json?: boolean; globals?: { [x: string]: unknown; }; globalSetup?: string | null; globalTeardown?: string | null; haste?: { computeSha1?: boolean; defaultPlatform?: string | null; forceNodeFilesystemAPI?: boolean; enableSymlinks?: boolean; hasteImplModulePath?: string; platforms?: string[]; throwOnModuleCollision?: boolean; hasteMapModulePath?: string; retainAllFiles?: boolean; }; injectGlobals?: boolean; reporters?: (string | [string, { [x: string]: unknown; }])[]; logHeapUsage?: boolean; lastCommit?: boolean; listTests?: boolean; maxConcurrency?: number; maxWorkers?: string | number; moduleDirectories?: string[]; moduleFileExtensions?: string[]; moduleNameMapper?: { [x: string]: string | string[]; }; modulePathIgnorePatterns?: string[]; modulePaths?: string[]; noStackTrace?: boolean; notify?: boolean; notifyMode?: string; onlyChanged?: boolean; onlyFailures?: boolean; openHandlesTimeout?: number; outputFile?: string; passWithNoTests?: boolean; preset?: string | null; prettierPath?: string | null; projects?: (string | { [x: string]: unknown; })[]; randomize?: boolean; replname?: string | null; resetMocks?: boolean; resetModules?: boolean; resolver?: string | null; restoreMocks?: boolean; rootDir?: string; roots?: string[]; runner?: string | [string, { [x: string]: unknown; }]; runTestsByPath?: boolean; runtime?: string; sandboxInjectedGlobals?: string[]; setupFiles?: string[]; setupFilesAfterEnv?: string[]; showSeed?: boolean; silent?: boolean; skipFilter?: boolean; skipNodeResolution?: boolean; slowTestThreshold?: number; snapshotResolver?: string; snapshotSerializers?: string[]; snapshotFormat?: { callToJSON?: boolean; compareKeys?: null; escapeRegex?: boolean; escapeString?: boolean; highlight?: boolean; indent?: number; maxDepth?: number; maxWidth?: number; min?: boolean; printBasicPrototype?: boolean; printFunctionName?: boolean; theme?: { comment?: string; content?: string; prop?: string; tag?: string; value?: string; }; }; errorOnDeprecated?: boolean; testEnvironment?: string; testEnvironmentOptions?: { [x: string]: unknown; }; testFailureExitCode?: number; testLocationInResults?: boolean; testMatch?: string | string[]; testNamePattern?: string; testPathIgnorePatterns?: string[]; testRegex?: string | string[]; testResultsProcessor?: string; testRunner?: string; testSequencer?: string; testTimeout?: number; transform?: { [x: string]: string | [string, unknown]; }; transformIgnorePatterns?: string[]; watchPathIgnorePatterns?: string[]; unmockedModulePathPatterns?: string[]; updateSnapshot?: boolean; useStderr?: boolean; verbose?: boolean; waitForUnhandledRejections?: boolean; watch?: boolean; watchAll?: boolean; watchman?: boolean; watchPlugins?: (string | [string, unknown])[]; workerIdleMemoryLimit?: string | number; workerThreads?: boolean; workerGracefulExitTimeout?: number; } — The jest configuration.


Links to this page: