Import, merge, or combine repositories into an Nx workspace using nx import. USE WHEN the user asks to adopt Nx across repos, move projects into a monorepo, or bring code/history from another repository.
Jest-specific guidance for nx import. For the basic "Jest Preset Missing" fix (create jest.preset.js, install deps), see SKILL.md. This file covers deeper Jest integration issues.
How @nx/jest Works
@nx/jest/plugin scans for jest.config.{ts,js,cjs,mjs,cts,mts} and creates a test target for each project.
Registers @nx/jest/plugin in nx.json — without this, no test targets are inferred
Updates namedInputs.production to exclude test files
Gotcha: nx add @nx/jest does NOT create jest.preset.js — that file is only generated when you run a generator (e.g. @nx/jest:configuration). For imports, you must create it manually (see "Jest Preset" section below).
Other gotcha: If you create jest.preset.js manually but skip npx nx add @nx/jest, the plugin won't be registered and nx run PROJECT:test will fail with "Cannot find target 'test'". You need both.
Jest Preset
The preset provides shared Jest configuration (test patterns, ts-jest transform, resolver, jsdom environment).
The preset path is relative from the project root to the workspace root. Subdirectory imports preserve the original relative path (e.g. ../../jest.preset.js), which resolves correctly if the import destination matches the source directory depth.
Testing Dependencies
Core (always needed)
pnpm add -wD jest ts-jest @types/jest @nx/jest
Environment-specific
DOM testing (React, Vue, browser libs): jest-environment-jsdom
Node testing (APIs, CLIs): no extra deps (Jest defaults to node env, but Nx preset defaults to jsdom)
Both @nx/jest/plugin and @nx/vite/plugin (which infers Vitest targets) coexist without conflicts — they detect different config files (jest.config.* vs vite.config.*).
Target naming: Both default to test. If a project somehow has both config files, rename one:
Projects migrating from Jest to Vitest (or workspaces with both) need different imports:
Jest (in test-setup.ts):
import '@testing-library/jest-dom';
Vitest (in test-setup.ts):
import '@testing-library/jest-dom/vitest';
If the source used Jest but the dest workspace uses Vitest for that project type, update the import path. Also add @testing-library/jest-dom to tsconfig types array.
Non-Nx Source: Test Script Rewriting
Nx rewrites package.json scripts during init. Test scripts get broken:
"test": "jest" → "test": "nx test" (circular if no executor configured)
"test": "vitest run" → "test": "nx test run" (broken — run becomes an argument)
Fix: Remove all rewritten test scripts. @nx/jest/plugin and @nx/vite/plugin infer test targets from config files.
CI Atomization
@nx/jest/plugin supports splitting tests per-file for CI parallelism:
This creates test-ci--src/lib/foo.spec.ts targets for each test file, enabling Nx Cloud distribution. Not relevant during import, but useful for post-import CI setup.
Common Post-Import Issues
"Cannot find target 'test'": @nx/jest/plugin not registered in nx.json. Run npx nx add @nx/jest or manually add the plugin entry.
"Cannot find module 'jest-preset'": jest.preset.js missing at workspace root. Create it (see SKILL.md).
"Cannot find type definition file for 'jest'": Missing @types/jest or tsconfig.spec.json doesn't have "types": ["jest", "node"].
Tests fail with "Cannot use import statement outside a module": ts-jest not installed or not configured as transform. Check jest.config.ts transform section.
Snapshot path mismatches: After import, __snapshots__ directories may have paths baked in. Run tests once with --updateSnapshot to regenerate.
Fix Order
Subdirectory Import (Nx Source)
npx nx add @nx/jest — registers plugin in nx.json (does NOT create jest.preset.js)
Create jest.preset.js manually (see "Jest Preset" section above)
Install deps: pnpm add -wD jest jest-environment-jsdom ts-jest @types/jest
Install framework test deps: @testing-library/react @testing-library/jest-dom (React), @vue/test-utils (Vue)
Verify tsconfig.spec.json has "types": ["jest", "node"]