Test Commands
Watch Mode
Run tests continuously, re-running on file changes:- Watch for changes in test files and source files
- Re-run affected tests automatically
- Display results in the terminal
- Provide interactive filtering options
Single Run
Run all tests once and exit:- CI/CD pipelines
- Pre-commit checks
- Verifying all tests pass before deployment
Coverage Report
Run tests with code coverage analysis:- Runs all tests once
- Generates coverage data using V8 provider
- Outputs coverage report in three formats:
- Text: Console output with coverage percentages
- JSON: Machine-readable coverage data
- HTML: Interactive browser-based report
Coverage Output
Terminal Report
The text reporter displays coverage in the terminal:HTML Report
The HTML report is generated in thecoverage/ directory:
- Browse coverage by file
- See line-by-line coverage highlighting
- Identify untested code paths
- Track coverage trends over time
Watch Mode Features
Interactive Filtering
When running in watch mode, Vitest provides keyboard shortcuts:a- Run all testsf- Run only failed testsp- Filter by test name patternt- Filter by test file patternq- Quit watch mode
Example Session
CI/CD Integration
For continuous integration, use the single-run command:.github/workflows/test.yml
Debugging Tests
Isolate Tests
Use.only to run a single test:
Skip Tests
Use.skip to temporarily disable tests:
Verbose Output
For detailed test output, use the--reporter=verbose flag:
Performance Tips
Run Specific Files
Run tests for a specific file:Run Tests Matching Pattern
Run tests with names matching a pattern:Related
- Testing Overview - Strategy and setup
- Writing Tests - Guidelines and examples
