@nx/jest plugin integrates Jest into your Nx workspace. It provides the jest executor for running unit tests, infers test targets from jest.config.ts files automatically, and supports SWC for faster TypeScript transforms.
Installation
What the plugin provides
Executors
The
jest executor runs your test suite with full Nx integration: caching, affected detection, and distributed execution.Generators
Add Jest configuration to any existing project. Migrate executor-based projects to inferred task mode.
Inferred tasks
Detects
jest.config.ts (or .js, .mjs, .cjs) files and infers a test target automatically.Generators
configuration
Add Jest configuration to an existing project. This creates ajest.config.ts file and wires up the test target.
ts-jest for faster transforms:
convert-to-inferred
Migrate existing projects that use the@nx/jest:jest executor to use the inferred task plugin (@nx/jest/plugin).
Executors
jest
Run Jest unit tests for a project. Supports all standard Jest CLI flags and adds Nx caching.Inferred tasks
When@nx/jest/plugin is registered in nx.json, Nx detects jest.config.ts (or .js, .mjs, .cjs, .cts, .mts) files and automatically infers a test target for each project that has one.
test target from project.json entirely is safe. Nx reads the Jest configuration directly from jest.config.ts.
Inferred task caching is based on the inputs defined in your
jest.config.ts and the project’s source files. Use nx show project myproject to inspect the inferred targets.Configuration examples
jest.config.ts with ts-jest
jest.config.ts with SWC
SWC provides significantly faster TypeScript transforms compared tots-jest:
