Performance: Vitest setup for unit testing
MEDIUM IMPACT
This setup affects initial test run speed and incremental test execution time during development.
/// vitest.config.ts import { defineConfig } from 'vitest/config'; import vue from '@vitejs/plugin-vue'; export default defineConfig({ plugins: [vue()], test: { include: ['tests/unit/**/*.spec.ts'], exclude: ['node_modules', 'dist'], environment: 'jsdom', watch: false } });
import { describe, it, expect } from 'vitest'; import { mount } from '@vue/test-utils'; // No config file, tests run with default settings // All files watched including node_modules // Test example it('renders component', () => { const wrapper = mount(MyComponent); expect(wrapper.text()).toContain('Hello'); });
| Pattern | File Watching | Test Startup Time | CPU Usage | Verdict |
|---|---|---|---|---|
| Default Vitest without config | Watches all files including node_modules | Slow (500ms+) | High CPU usage | [X] Bad |
| Vitest with focused config and excludes | Watches only test files and source | Fast (200ms) | Low CPU usage | [OK] Good |