project.json:

1//... 2"my-app": { 3 "targets": { 4 //... 5 "test": { 6 "executor": "@nx/vite:test", 7 //... 8 //... 9 "options": { 10 "config": "apps/my-app/vite.config.ts" 11 } 12 //... 13 } 14 } 15} 16
Nx 15 and lower use @nrwl/ instead of @nx/
1nx test my-app 2

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:

1"my-app": { 2 "targets": { 3 //... 4 "test": { 5 "executor": "@nx/vite:test", 6 //... 7 //... 8 "options": { 9 "config": "apps/my-app/vite.config.ts" 10 }, 11 "configurations": { 12 "watch": { 13 "watch": true 14 } 15 } 16 } 17 } 18} 19
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:

1nx run my-app:test --watch 2

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

testFiles

Array<string>

No description available.

watch

boolean
Default: false

Enable watch mode