Nx plugin for Jest testing with executors, generators, and configuration utilities for monorepo testing workflows.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Jest test runner executor with support for batch execution, affected testing, and Nx-specific optimizations. The executor provides comprehensive test execution capabilities including coverage reporting, watch mode, and integration with Nx's caching and parallelization features.
Main Jest test runner executor with comprehensive configuration options and batch execution support.
/**
* Jest test executor with Nx-specific optimizations
* @param options - Jest execution options
* @param context - Nx executor context
* @returns Promise resolving to execution result
*/
function jestExecutor(
options: JestExecutorOptions,
context: ExecutorContext
): Promise<{ success: boolean }>;
/**
* Batch Jest executor for running multiple Jest projects in parallel
* @param taskGraph - Graph of tasks to execute
* @param inputs - Map of project names to Jest executor options
* @param overrides - Global Jest executor options to apply to all projects
* @param context - Nx executor context
* @returns Promise resolving to batch execution results
*/
function batchJest(
taskGraph: TaskGraph,
inputs: Record<string, JestExecutorOptions>,
overrides: JestExecutorOptions,
context: ExecutorContext
): Promise<BatchResults>;Complete configuration interface for Jest test execution.
interface JestExecutorOptions {
/** Enable code coverage collection and reporting */
codeCoverage?: boolean;
/** Path to Jest configuration file */
config?: string;
/** Detect handles that prevent Jest from exiting cleanly */
detectOpenHandles?: boolean;
/** Track and log memory usage */
logHeapUsage?: boolean;
/** Detect memory leaks in tests */
detectLeaks?: boolean;
/** Path to Jest configuration file (required) */
jestConfig: string;
/** Run specific test file */
testFile?: string;
/** Stop after first test failure or N failures */
bail?: boolean | number;
/** Run in continuous integration mode */
ci?: boolean;
/** Force color output */
color?: boolean;
/** Delete Jest cache directory before running tests */
clearCache?: boolean;
/** Find and run tests related to changed files */
findRelatedTests?: string;
/** Force Jest to exit after tests complete */
forceExit?: boolean;
/** Print test results in JSON format */
json?: boolean;
/** Maximum number of worker processes */
maxWorkers?: number | string;
/** Run tests only for changed files */
onlyChanged?: boolean;
/** Run tests for files changed since specified commit */
changedSince?: string;
/** Write test results to specified file */
outputFile?: string;
/** Allow empty test suites to pass */
passWithNoTests?: boolean;
/** Randomize test execution order */
randomize?: boolean;
/** Run tests serially in current process */
runInBand?: boolean;
/** Print Jest configuration and exit */
showConfig?: boolean;
/** Suppress output except for errors */
silent?: boolean;
/** Run tests matching specified name pattern */
testNamePattern?: string;
/** Ignore tests matching these patterns */
testPathIgnorePatterns?: string[];
/** Run tests matching these patterns */
testPathPatterns?: string[];
/** Enable colored output */
colors?: boolean;
/** List of test reporters to use */
reporters?: string[];
/** Enable verbose output */
verbose?: boolean;
/** List of coverage reporters to use */
coverageReporters?: string[];
/** Directory for coverage reports */
coverageDirectory?: string;
/** Custom test results processor */
testResultsProcessor?: string;
/** Update snapshots during test run */
updateSnapshot?: boolean;
/** Use stderr for output instead of stdout */
useStderr?: boolean;
/** Watch files for changes and rerun tests */
watch?: boolean;
/** Watch all files for changes */
watchAll?: boolean;
/** Include location information in test results */
testLocationInResults?: boolean;
/** Global test timeout in milliseconds */
testTimeout?: number;
/**
* Setup file configuration
* @deprecated Use the setupFilesAfterEnv option in Jest configuration instead
*/
setupFile?: string;
}Usage Examples:
import { jestExecutor } from "@nx/jest";
import { ExecutorContext } from '@nx/devkit';
// Basic test execution
const result = await jestExecutor({
jestConfig: "./jest.config.ts",
codeCoverage: true
}, context);
// Advanced configuration with specific options
const advancedResult = await jestExecutor({
jestConfig: "./jest.config.ts",
codeCoverage: true,
testEnvironment: "jsdom",
maxWorkers: 4,
bail: 1,
verbose: true,
coverageReporters: ["html", "lcov", "text-summary"],
testPathPatterns: ["**/*.spec.ts"]
}, context);
// Running specific test file
const specificTest = await jestExecutor({
jestConfig: "./jest.config.ts",
testFile: "src/app/component.spec.ts"
}, context);The Jest executor is configured in the project's project.json or workspace.json:
{
"targets": {
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "apps/my-app/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
}
}
}For running multiple Jest projects in parallel:
import { batchJest } from "@nx/jest";
// Batch execution automatically handles parallelization
// and is used internally by Nx when running multiple projects
const batchResults = await batchJest(
taskGraph,
{
"project1": { jestConfig: "./apps/project1/jest.config.ts" },
"project2": { jestConfig: "./apps/project2/jest.config.ts" }
},
{ ci: true }, // Global overrides applied to all projects
context
);interface TaskGraph {
// Graph structure for task dependencies and execution order
}
interface BatchResults {
// Results from batch execution of multiple tasks
}Install with Tessl CLI
npx tessl i tessl/npm-nx--jest