project.json:

//... "my-app": { "targets": { //... "test": { "executor": "@nx/vite:test", //... //... "options": { "config": "apps/my-app/vite.config.ts" } //... } } }
Nx 15 and lower use @nrwl/ instead of @nx/
nx test my-app

Examples

To run testing in watch mode, you can create a new configuration within your test target, and have watch set to true. For example:

"my-app": { "targets": { //... "test": { "executor": "@nx/vite:test", //... //... "options": { "config": "apps/my-app/vite.config.ts" }, "configurations": { "watch": { "watch": true } } } } }
Nx 15 and lower use @nrwl/ instead of @nx/

And then run nx run my-app:test:watch.

Alternatively, you can just run the default test target with the --watch flag preset, like so:

nx run my-app:test --watch

Options

coverage

boolean
Default: false

Enable coverage report

mode

string
Default: test
Accepted values: test, benchmark, typecheck

The mode that vitest will run on

update

u
boolean
Default: false

Update snapshots

config

string

The path to the local vitest config

passWithNoTests

boolean
Default: true

Pass the test even if no tests are found

reporters

Array<string>

An array of reporters to pass to vitest

reportsDirectory

string

Directory to write coverage report to.

testNamePattern

string

Run tests with full names matching the pattern

testFile

string

The name of the file to test.

watch

boolean
Default: false

Enable watch mode