Vitest is a fast test runner built on Vite.
The @nx/vitest plugin adds inferred Vitest targets, a project configuration generator, and CI-friendly test splitting.
You can use Vitest with Nx without the plugin and still get task caching, task orchestration, and the project graph.
Requirements
Section titled “Requirements”The @nx/vitest plugin supports the following package versions.
| Package | Supported Versions |
|---|---|
vitest | ^3.0.0 || ^4.0.0 |
Nx generators install the latest supported versions automatically when scaffolding new projects.
Add to an existing workspace
Section titled “Add to an existing workspace”nx add @nx/vitestVerify inferred tasks
Section titled “Verify inferred tasks”Nx infers Vitest tasks from your Vitest or Vite config files. To confirm which targets were created, open the project details view in Nx Console or run:
nx show project my-appAdd Vitest to a project
Section titled “Add Vitest to a project”Use the configuration generator to set up a project with Vitest:
nx g @nx/vitest:configuration --project=my-appThe generator accepts framework-specific options. Pass the right flags for your project type:
nx g @nx/vitest:configuration --project=my-react-lib --uiFramework=reactSets up Vitest with React JSX support and jsdom test environment.
nx g @nx/vitest:configuration --project=my-vue-lib --uiFramework=vueSets up Vitest with Vue SFC support and jsdom test environment.
nx g @nx/vitest:configuration --project=my-angular-lib --uiFramework=angularConfigures Vitest for Angular with the appropriate test setup.
nx g @nx/vitest:configuration --project=my-node-lib --testEnvironment=nodeUses the node test environment instead of the default jsdom.
See the full configuration generator reference for all options.
Local development
Section titled “Local development”Run Vitest through Nx so caching and the project graph work together.
nx test my-appnx test my-app --watchnx test my-app -- MyComponent.spec.tsnx test my-app --uinx test my-app --coverageConfiguration
Section titled “Configuration”How tasks are inferred
Section titled “How tasks are inferred”The @nx/vitest plugin creates a target for any project that has a Vitest or Vite config file with test settings. The plugin looks for:
vitest.config.jsvitest.config.tsvitest.config.mjsvitest.config.mtsvitest.config.cjsvitest.config.ctsvite.config.js(withtestconfiguration)vite.config.ts(withtestconfiguration)vite.config.mjs(withtestconfiguration)vite.config.mts(withtestconfiguration)vite.config.cjs(withtestconfiguration)vite.config.cts(withtestconfiguration)
To view inferred tasks, open the project details view in Nx Console or run nx show project my-app.
Plugin options
Section titled “Plugin options”Configure the plugin in nx.json:
{ "plugins": [ { "plugin": "@nx/vitest", "options": { "testTargetName": "test", "ciTargetName": "test-ci", "ciGroupName": "Unit Tests (CI)", "testMode": "watch" } } ]}| Option | Type | Default | Description |
|---|---|---|---|
testTargetName | string | test | Name of the inferred local target. |
ciTargetName | string | none | Creates a CI-only target used for atomized runs. |
ciGroupName | string | derived from ciTargetName | Display name for the atomized CI group. |
testMode | watch or run | watch | Determines whether Nx runs vitest (watch) or vitest run (single run). |
There is no single "disable" flag for inference. Use include and exclude to scope which projects each plugin instance applies to.
Configure unit and e2e separately
Section titled “Configure unit and e2e separately”If you use Vitest for unit and e2e tests, configure the plugin twice with different include and exclude patterns.
{ "plugins": [ { "plugin": "@nx/vitest", "exclude": ["e2e/**/*"], "options": { "testTargetName": "test", "testMode": "watch" } }, { "plugin": "@nx/vitest", "include": ["e2e/**/*"], "options": { "testTargetName": "e2e", "ciTargetName": "e2e-ci", "ciGroupName": "E2E Tests (CI)", "testMode": "run" } } ]}Set up CI
Section titled “Set up CI”In CI, Nx runs nx affected to rebuild and retest only the projects a change touches, and caches results to skip repeated work.
For a complete pipeline, see Set up CI.