Running Tests
Commands
| Command | Description |
|---|---|
npm test | Run tests in watch mode (re-runs on changes) |
npm run test:run | Single test run (CI-friendly) |
npm run test:coverage | Generate coverage report |
npm run test:ui | Open Vitest UI in browser |
Watch Mode
bash
npm testVitest watches for file changes and re-runs affected tests. Press h in the terminal for interactive options.
Coverage
bash
npm run test:coverageGenerates a coverage report showing which lines, branches, and functions are tested.
Vitest UI
bash
npm run test:uiOpens a browser-based dashboard at http://localhost:51204/__vitest__/ with:
- Test file browser
- Individual test results
- Re-run capabilities
- Coverage visualization
Configuration
Vitest is configured in vitest.config.ts:
typescript
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
environment: 'happy-dom',
setupFiles: ['./tests/setup.ts'],
}
})