Agent skill
vitest-config
Generates vitest.config.ts for unit testing configuration. Configures Vitest with Vue, TypeScript support, coverage thresholds, and test environment settings.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/vitest-config
SKILL.md
Vitest Config Skill
Purpose
Generate the vitest.config.ts file for unit testing configuration with Vitest.
⚠️ CONDITIONAL EXECUTION
This skill should ONLY be used if the project uses Vitest instead of Jest.
Test Framework Detection:
- Check
package.jsonfor test framework dependency:- If
"jest"found → SKIP THIS SKILL (use jest-config skill instead) - If
"vitest"found → EXECUTE THIS SKILL - If neither found → PROMPT USER: "Which test framework do you want to use: Jest or Vitest?"
- If
🚨 PRE-REQUISITE: REQUIRED DEPENDENCIES
CRITICAL: Before generating vitest.config.ts, verify package.json includes ALL required Vitest dependencies.
Required Vitest Packages
The following packages MUST be in package.json devDependencies BEFORE creating vitest.config.ts:
-
vitest- Core test framework- Why: Main testing runtime
- Error if missing: "Cannot find module 'vitest'"
-
@vitest/coverage-v8- Coverage provider- Why: Required by
coverage.provider: 'v8'in vitest.config.ts - Error if missing: "Coverage provider 'v8' not found"
- Impact: Coverage reports won't work
- Why: Required by
-
jsdom- DOM environment- Why: Required by
environment: 'jsdom'in vitest.config.ts for Vue component testing - Error if missing: "Environment 'jsdom' not found. You need to install jsdom package"
- Impact: Tests cannot run (blocks all testing)
- Alternative:
happy-dom(but jsdom is more compatible with Vue ecosystem)
- Why: Required by
-
@vitest/ui- Optional UI visualization- Why: Interactive test UI for debugging
- Error if missing: None (optional feature)
Validation Check
BEFORE proceeding with file generation, run this validation:
# Check if all required Vitest packages are in package.json
required_packages=("vitest" "@vitest/coverage-v8" "jsdom")
missing_packages=()
for pkg in "${required_packages[@]}"; do
if ! grep -q "\"$pkg\":" package.json 2>/dev/null; then
missing_packages+=("$pkg")
fi
done
if [ ${#missing_packages[@]} -gt 0 ]; then
echo "❌ ERROR: Missing required Vitest dependencies in package.json:"
printf ' - %s\n' "${missing_packages[@]}"
echo ""
echo "SOLUTION: Update package-json skill to include these packages"
echo "Then re-run npm install before generating vitest.config.ts"
exit 1
else
echo "✅ All required Vitest dependencies found in package.json"
fi
What To Do If Packages Are Missing
DO NOT PROCEED with generating vitest.config.ts. Instead:
- Go back to package-json skill
- Add missing packages to the versions.json configuration:
json
"devDependencies": { "vitest": "latest", "@vitest/ui": "latest", "@vitest/coverage-v8": "latest", "jsdom": "latest" } - Regenerate package.json with complete dependencies
- Run
npm installto install packages - THEN return to this skill to generate vitest.config.ts
Why this order matters:
- vitest.config.ts imports from these packages
- Configuration references these packages by name
- Tests will fail immediately without these runtime dependencies
- Better to catch missing deps during setup than during first test run
🚨 MANDATORY FILE COUNT
This skill MUST create exactly 1 file:
vitest.config.ts(TypeScript format - recommended for Vite projects)
🔍 BEFORE GENERATING - RESEARCH REQUIRED
⚠️ Verify current Vitest ecosystem to ensure best practices
Required Research Steps:
- Vitest Version: Check current Vitest version and features
- Verify latest stable version
- Check for new configuration options
- Coverage Provider: Verify
@vitest/coverage-v8is still recommended- Check if coverage provider packages are maintained
- Verify v8 vs istanbul performance and accuracy
- Vue Plugin: Verify
@vitejs/plugin-vuecompatibility- Ensure plugin version matches Vite version
- Check for breaking changes in Vue plugin
- Test Environment: Verify
jsdomorhappy-domrecommendationjsdom- More complete, slower, better compatibilityhappy-dom- Faster, lighter, good for most use cases
- TypeScript Support: Verify Vitest's built-in TypeScript support
- No additional transformer needed (unlike Jest)
- Uses Vite's built-in esbuild transformation
- Coverage Configuration: Check current coverage threshold recommendations
- Verify recommended coverage levels (lines, branches, functions, statements)
- File Format: Verify
.tsformat is still preferred- Alternative:
.js,.mtsformats
- Alternative:
Output
Create the file: vitest.config.ts
Supported Format:
vitest.config.ts(TypeScript - strict preferred format, best for Vite projects)
Alternative Formats (only if .ts not preferred):
vitest.config.js(JavaScript)vitest.config.mts(ES Module TypeScript)
Example File
See: examples.md in this directory for complete examples and detailed explanations.
⚠️ IMPORTANT: The examples.md file contains January 2026 configurations. Always verify current Vitest ecosystem before using.
Configuration Decisions
Globals: Disabled (globals: false)
Decision: Explicit imports recommended for modern projects
// Requires explicit imports (recommended)
import { describe, it, expect } from 'vitest';
Why:
- ✅ Better IDE support and auto-completion
- ✅ Explicit dependencies (easier to understand)
- ✅ No global namespace pollution
- ✅ More modern TypeScript pattern
Alternative (globals: true):
- No imports needed (like Jest)
- Good for migrating from Jest
- May hide dependencies
Coverage Provider: v8
Decision: Use @vitest/coverage-v8 (recommended)
Why:
- ✅ Faster (native V8 instrumentation)
- ✅ More accurate (actual code execution)
- ✅ Better source map support
- ✅ Default for Vitest
Alternative: @vitest/coverage-istanbul (for Jest compatibility)
Test Environment: jsdom
Decision: Use jsdom for maximum compatibility
Why:
- ✅ Complete DOM API implementation
- ✅ Better compatibility with third-party libraries
- ✅ Industry standard for Vue testing
Alternative: happy-dom (faster, lighter, but may have compatibility issues)
Execution Checklist
- Detect test framework from package.json (Vitest vs Jest)
- If Jest detected, skip this skill entirely
- If Vitest detected, proceed with research
- CRITICAL: Verify package.json has required Vitest dependencies:
-
vitest(test framework) -
@vitest/coverage-v8(coverage provider - REQUIRED for coverage) -
jsdom(DOM environment - REQUIRED for Vue component testing) -
@vitest/ui(optional UI visualization) - If any are missing, STOP and update package.json first
-
- Research current Vitest version and features
- Verify
@vitest/coverage-v8is still recommended - Verify
@vitejs/plugin-vuecompatibility with Vite version - Verify
jsdomvshappy-domrecommendation - Check coverage threshold best practices
- Verify path alias resolution (should inherit from vite.config.ts)
- Create
vitest.config.tswith current standards - Include coverage thresholds (minimum 80% recommended)
- Configure globals: false (explicit imports)
- Verify file format is still recommended (not deprecated)
🛑 BLOCKING VALIDATION CHECKPOINT
STOP! Before proceeding to the next skill, verify:
Automated Verification
Run this command to verify the file exists:
if [ -f "vitest.config.ts" ] || [ -f "vitest.config.js" ] || [ -f "vitest.config.mts" ] || grep -q "\"vitest\":" package.json 2>/dev/null; then
echo "✓ Vitest configuration found"
if [ -f "vitest.config.ts" ]; then
echo "✓ Using vitest.config.ts (preferred format)"
fi
# Check for Jest conflict
if grep -q "\"jest\"" package.json 2>/dev/null; then
echo "⚠ WARNING: Both Vitest and Jest detected in package.json"
echo " Consider using only one test framework"
fi
else
echo "✗ Vitest configuration missing"
exit 1
fi
Manual Verification
- ✓
vitest.config.tsexists at project root - ✓ File uses TypeScript format (exports
defineConfig) - ✓ File includes
@vitejs/plugin-vueplugin - ✓ File includes
test.globals: false(explicit imports) - ✓ File includes
test.environment: 'jsdom'for DOM testing - ✓ File includes coverage configuration with v8 provider
- ✓ File includes coverage thresholds (80%+ recommended)
- ✓ Path aliases are resolved (via Vite config inheritance)
- ✓ No Jest configuration conflict in package.json
- ✓ Coverage provider packages in package.json devDependencies
If Validation Fails
DO NOT PROCEED to the next skill. Create or fix the missing/incorrect file immediately.
Notes
- Conditional Execution: Only use if project uses Vitest (not Jest)
- Recommended: Vitest is officially recommended for Vue 3 + Vite projects
- Performance: Faster than Jest due to Vite's native ESM and esbuild
- No Transformers: Vitest uses Vite's built-in transformation (no ts-jest needed)
- ESM Native: No
transformIgnorePatternsneeded (handles ESM automatically) - Coverage Provider: v8 is default and recommended for accuracy and performance
- Test Environment: jsdom provides complete DOM APIs for Vue component testing
- Globals Disabled: Explicit imports improve IDE support and code clarity
- Hot Module Reload: Vitest supports HMR for faster development
- TypeScript Format:
.tsformat integrates seamlessly with Vite ecosystem - Coverage Thresholds: Include minimum coverage requirements (80%+ recommended)
- Path Aliases: Automatically resolved from vite.config.ts (no duplication needed)
- Always verify current ecosystem - Vitest evolves with Vite releases
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?