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.
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" } } ]}CI Considerations
Section titled “CI Considerations”See Set Up CI for a complete CI configuration guide.
Build and Test Only What Changed
Section titled “Build and Test Only What Changed”nx affected -t testThis uses the project graph to determine which projects are affected by your changes and only runs tasks for those. Read more about the benefits of nx affected.
Remote Caching
Section titled “Remote Caching”Share test and e2e cache results across your team and CI with remote caching:
nx connectTask Splitting for Slow Tests
Section titled “Task Splitting for Slow Tests”For slow test suites (e.g. E2E or integration tests), set ciTargetName to split tests by file for distributed CI runs. Each test file becomes its own cacheable CI task with better caching and retries. See split e2e tasks for details.
If you use testMode: "watch" locally, use testMode: "run" for CI to keep runs deterministic.
Feature-Based Testing
Section titled “Feature-Based Testing”Organize tests by feature to get better cache hits and more targeted CI runs. See the feature-based testing guide for strategies on structuring tests in a monorepo.