vitest
npx machina-cli add skill DigitalPine/claude-skills/vitest --openclawVitest Setup & Configuration Expert
Trigger Condition
Use this skill when setting up Vitest testing in new or existing projects, auditing test configurations, fixing issues, migrating from Jest, or modernizing existing Vitest configurations to current best practices (Vitest 4.0+, October 2025).
Example scenarios:
- "Set up Vitest for this project"
- "Audit my Vitest configuration"
- "Check if my Vitest config follows best practices"
- "Fix deprecated Vitest patterns"
- "Update Vitest to v4.0+"
- "Add browser testing with Vitest"
- "Migrate from Jest to Vitest"
- "Configure Vitest for a monorepo"
- "Add visual regression testing"
- "Why are my Vitest tests slow?"
- "Review my test setup"
Core Competencies
This skill provides:
- ✅ Modern Vitest 4.0+ setup and configuration patterns
- ✅ Browser Mode setup (playwright, webdriverio, preview providers)
- ✅ Projects-based monorepo configuration (workspaces deprecated)
- ✅ Coverage configuration (V8 and Istanbul)
- ✅ Visual regression testing setup
- ✅ Migration guidance from Jest or older Vitest versions
- ✅ TypeScript configuration and type safety
- ✅ Performance optimization and parallel execution
- ✅ CI/CD integration patterns
Critical Context (October 2025)
Version Requirements
- Vitest 4.0 is the latest stable release
- Requires Vite >=6.0.0 and Node.js >=20.0.0
- Major breaking changes from v3.x (see migration guide)
Major Architectural Changes
- Workspaces → Projects (v3.2+): Workspace config deprecated; use
projectsarray in root config - Browser Mode Stable (v4.0): No longer experimental; requires separate provider packages
- V8 Coverage Improvements (v4.0): AST-based remapping replaces v8-to-istanbul
- Pool Architecture Rewrite (v4.0): Tinypool removed; unified worker management
- Module Runner (v4.0): Replaces vite-node internally
Key Deprecations & Removals (v4.0)
- ❌
coverage.allandcoverage.extensionsremoved - ❌
workspaceconfig option (useprojectsinstead) - ❌
poolMatchGlobsandenvironmentMatchGlobs(useprojectsinstead) - ❌
deps.external,deps.inline(useserver.deps.*variants) - ❌
basicreporter removed - ❌
maxThreads/maxForks(usemaxWorkersinstead)
Required Reading
⚠️ BEFORE providing Vitest guidance, read the appropriate reference:
| Scenario | REQUIRED Reading |
|---|---|
| Auditing existing v4+ project | vitest-migration-guide.md — Breaking changes are extensive |
| Upgrading from v3.x | vitest-migration-guide.md — Must understand removed options |
| Browser testing setup | vitest-browser-mode.md — Provider syntax changed completely |
| Coverage configuration | vitest-config-reference.md — coverage.all removed in v4 |
| Any configuration question | vitest-config-reference.md — Many options deprecated |
Why this matters: Vitest 4.0 has major breaking changes. Training data may contain v3 patterns that cause errors in v4 projects. Always verify against references.
Reference Documentation
Detailed reference files in references/:
vitest-config-reference.md- Complete configuration options, best practices, common patternsvitest-cli-reference.md- CLI commands, options, workflowsvitest-browser-mode.md- Browser testing setup, providers, component testingvitest-migration-guide.md- Breaking changes, version migrations, Jest to Vitest
Configuration Templates
The assets/ directory contains ready-to-use configuration templates:
vitest.config.basic.ts- Minimal Node.js testing setupvitest.config.browser.ts- Browser mode with Playwrightvitest.config.projects.ts- Multi-project/monorepo setupvitest.config.coverage.ts- Comprehensive coverage configurationvitest.shared.ts- Shared configuration pattern for projectspackage.json.example- npm scripts and dependencies
Workflow Process
Phase 1: Discovery & Assessment
Always start by understanding the current state:
-
Check for existing configuration:
- Look for
vitest.config.ts/js,vite.config.ts/js - Check
package.jsonfor vitest version and scripts - Identify existing test files (
.test.,.spec.patterns)
- Look for
-
Assess project structure:
- Single package or monorepo?
- Framework used (React, Vue, Svelte, etc.)?
- TypeScript or JavaScript?
- Current test runner (Jest, Mocha, etc.)?
-
Identify requirements:
- Node.js testing only or browser testing needed?
- Coverage requirements?
- Component testing needs?
- Visual regression testing?
- CI/CD integration requirements?
Phase 2: Installation & Setup
For new projects (no existing testing):
-
Install Vitest:
pnpm add -D vitest -
Choose and install additional packages based on needs:
# For browser testing with Playwright pnpm add -D @vitest/browser-playwright # For coverage (V8 is default, Istanbul available) pnpm add -D @vitest/coverage-v8 # or pnpm add -D @vitest/coverage-istanbul # For jsdom/happy-dom environments pnpm add -D jsdom # or pnpm add -D happy-dom # For UI interface pnpm add -D @vitest/ui -
Use appropriate config template from
assets/directory -
Add npm scripts to
package.json:{ "scripts": { "test": "vitest", "test:run": "vitest run", "test:ui": "vitest --ui", "test:coverage": "vitest run --coverage" } }
For existing projects (migrating or upgrading):
- Check current vitest version:
pnpm list vitest - If migrating from Jest, consult
vitest-migration-guide.md - If upgrading from v3.x or earlier, review breaking changes
- Update dependencies to latest versions
- Migrate deprecated configuration options
Phase 3: Configuration
Key configuration principles:
- Start minimal - Vitest works with zero config when using Vite
- Use projects for complexity - Multi-environment or monorepo setups
- Explicit coverage.include - Required in v4.0+ for uncovered file reporting
- TypeScript support - Use
defineConfigfromvitest/configfor type safety - Shared configs - Use
vitest.shared.tspattern for projects
Common configuration patterns:
- Node.js only: Use
vitest.config.basic.tstemplate - Browser testing: Use
vitest.config.browser.tstemplate - Monorepo: Use
vitest.config.projects.tstemplate - Mixed environments: Use projects with different environments
Phase 4: Verification
- Run tests:
pnpm test:run - Check coverage:
pnpm test:coverage - Verify browser mode (if configured): Tests should open browser
- Check CI compatibility: Ensure headless mode works
Phase 5: CI/CD Integration
Key CI considerations:
- Environment detection: Vitest auto-detects CI and disables watch mode
- Headless browser mode: Set
browser.headless: truefor CI - Coverage reporting: Use appropriate reporters for CI platforms
- Sharding support: Use
--shard=1/3syntax for parallel CI execution - Fail-fast: Consider
--bail=1to stop on first failure
Decision Trees
Which Provider for Browser Testing?
Choose Playwright when:
- ✅ Need Firefox, Webkit, or Chromium support
- ✅ Want visual regression testing (screenshots, traces)
- ✅ Most comprehensive feature set
- ✅ Recommended default
Choose WebdriverIO when:
- ✅ Already using WebdriverIO in project
- ✅ Need Safari support on macOS
- ✅ Existing WebdriverIO infrastructure
Choose Preview when:
- ✅ Development/prototyping only
- ✅ Cannot install browser dependencies
- ⚠️ Not for production/CI
Projects vs Single Config?
Use Projects when:
- ✅ Monorepo with multiple packages
- ✅ Need different test environments (node + browser)
- ✅ Different configurations for unit vs integration tests
- ✅ Need to run tests in parallel across configs
Use Single Config when:
- ✅ Simple single-package project
- ✅ All tests use same environment
- ✅ No complex configuration requirements
Coverage Provider Choice?
Use V8 (default) when:
- ✅ Best performance
- ✅ Works with Vite's transformation
- ✅ Recommended default
Use Istanbul when:
- ✅ Need more accurate coverage for edge cases
- ✅ Migrating from Jest with Istanbul
- ✅ Specific reporter compatibility needs
Common Patterns & Solutions
Pattern: Node + Browser Tests
Use projects to separate environments:
export default defineConfig({
test: {
projects: [
{
test: {
name: 'unit',
environment: 'node',
include: ['**/*.unit.test.ts']
}
},
{
test: {
name: 'browser',
browser: {
enabled: true,
provider: playwright(),
instances: [{ browser: 'chromium' }]
},
include: ['**/*.browser.test.ts']
}
}
]
}
})
Pattern: Shared Configuration for Monorepo
Create vitest.shared.ts:
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true,
setupFiles: ['./test-setup.ts']
}
})
Then in each package:
import { defineProject, mergeConfig } from 'vitest/config'
import configShared from '../../vitest.shared.js'
export default mergeConfig(
configShared,
defineProject({
test: {
environment: 'jsdom'
}
})
)
Pattern: Coverage with Uncovered Files
Important: In v4.0+, must explicitly define coverage.include:
export default defineConfig({
test: {
coverage: {
enabled: true,
provider: 'v8',
include: ['src/**/*.{ts,tsx}'],
exclude: [
'src/**/*.test.{ts,tsx}',
'src/**/*.spec.{ts,tsx}',
'src/**/__tests__/**'
],
reporter: ['text', 'html', 'lcov']
}
}
})
Anti-Patterns & Common Mistakes
❌ Using deprecated workspace config
// DON'T - workspace is deprecated
export default defineConfig({
test: {
workspace: './vitest.workspace.js'
}
})
// DO - use projects instead
export default defineConfig({
test: {
projects: ['./packages/*']
}
})
❌ Missing coverage.include in v4.0+
// DON'T - will only cover files that were imported during tests
export default defineConfig({
test: {
coverage: {
enabled: true
}
}
})
// DO - explicitly define what to cover
export default defineConfig({
test: {
coverage: {
enabled: true,
include: ['src/**/*.ts']
}
}
})
❌ Using old browser provider string syntax
// DON'T - old v3.x syntax
export default defineConfig({
test: {
browser: {
provider: 'playwright'
}
}
})
// DO - v4.0+ requires provider object
import { playwright } from '@vitest/browser-playwright'
export default defineConfig({
test: {
browser: {
provider: playwright()
}
}
})
❌ Using removed pool options
// DON'T - removed in v4.0
export default defineConfig({
test: {
maxThreads: 4,
poolOptions: {
threads: { isolate: false }
}
}
})
// DO - use new unified syntax
export default defineConfig({
test: {
maxWorkers: 4,
isolate: false
}
})
Troubleshooting Guide
Issue: Tests not being discovered
Check:
- Test files match pattern:
**/*.{test,spec}.?(c|m)[jt]s?(x) - Files not in
excludepatterns - Check
includeconfiguration if customized - Use
vitest listto see what tests Vitest found
Issue: Module resolution errors
Solutions:
- Ensure Vite config has correct
resolve.aliasentries - Check
tsconfig.jsonpaths match Vite config - Add
/// <reference types="vitest/config" />to vite.config.ts - For external dependencies, configure
server.deps.inline
Issue: Coverage shows 0% or missing files
In v4.0+:
- Must explicitly set
coverage.includeglob patterns - Check patterns actually match your source files
- Verify files aren't in
coverage.exclude - Use
coverage.all: trueonly if really needed (deprecated but available)
Issue: Browser tests failing in CI
Check:
- Set
browser.headless: truefor CI environments - Install browser binaries:
npx playwright installor similar - Use
--browser.headlessCLI flag - Configure appropriate timeouts for CI
Issue: Slow test execution
Optimization strategies:
- Enable parallel execution:
fileParallelism: true(default) - Increase workers:
maxWorkers: <number> - Use projects for different test types
- Consider disabling
isolatefor unit tests (with caution) - Use
--no-cacheto rule out cache corruption
Output & Next Steps
After completing setup, provide the user with:
- Summary of configuration - What was set up and why
- Test commands - How to run tests, coverage, UI
- File locations - Where configs and test files are
- Next steps - Suggestions for writing first tests or migrations
- Resources - Links to relevant docs or examples
When NOT to Use This Skill
- User wants to use a different test framework (Jest, Mocha, etc.)
- Testing is not relevant to the current task
- User explicitly wants to avoid testing setup
Collaboration with Other Skills
This skill works well with:
- nextjs-16-setup: For Next.js projects needing testing
- react-ink-cli: For CLI app testing
- xmcp-server-setup: For MCP server testing
Success Criteria
Configuration is successful when:
- ✅ Tests run without errors
- ✅ Configuration follows Vitest 4.0+ best practices
- ✅ Coverage reports generated (if configured)
- ✅ Browser tests work (if configured)
- ✅ CI/CD integration functional (if required)
- ✅ No deprecated options used
- ✅ TypeScript types working correctly
Source
git clone https://github.com/DigitalPine/claude-skills/blob/main/plugins/vitest/skills/vitest/SKILL.mdView on GitHub Overview
This skill helps you set up Vitest in new or existing projects, audit configurations for v4.0+ best practices, fix deprecated patterns, and migrate from Jest. It also covers browser mode, monorepo projects, coverage configuration, visual regression testing, and CI integration.
How This Skill Works
The skill analyzes your current Vitest setup, maps it to Vitest 4.0+ patterns, and references migration guides and official docs to generate concrete upgrade steps. It provides ready to use config templates, guidance for browser mode and providers, and CI integration patterns to ensure reliable, fast tests with proper coverage reporting.
When to Use It
- Setting up Vitest for a new project
- Auditing an existing Vitest configuration for v4.0+ best practices
- Migrating from Jest to Vitest
- Adding browser mode and visual regression testing
- Configuring Vitest in a monorepo or workspace-less project
Quick Start
- Step 1: Install vitest (and providers for browser mode if needed) and ensure Vite >= 6.0.0 is in place
- Step 2: Replace Jest patterns or outdated Vitest options with a projects based config and set up coverage
- Step 3: Run tests locally, then run in CI and iterate on any deprecations or performance tweaks
Best Practices
- Read the vitest-migration-guide before making changes
- Use the projects config instead of workspace to align with v4.0+
- Configure coverage with V8 remapping and avoid deprecated options like coverage.all
- Enable browser mode with a supported provider and keep provider configs isolated
- Tune performance with parallel execution and appropriate maxWorkers for CI
Example Use Cases
- Set up Vitest for a new Vite project with Vite 6+
- Audit an existing Vitest v3 config and migrate to v4.0+
- Migrate a Jest test suite to Vitest with improved performance
- Configure browser mode using a Playwright provider for component tests
- Add visual regression testing and CI integration to the Vitest suite