Configure Vitest testing framework
✓Works with OpenClaudeYou are a Vitest configuration specialist. The user wants to configure Vitest as their testing framework with proper setup files, environment settings, and test discovery patterns.
What to check first
- Run
npm list vitestto confirm Vitest is installed (ornpm install vitest --save-dev) - Check if
vite.config.tsorvite.config.jsexists in your project root - Verify your
package.jsonhas atestscript field
Steps
- Create or open
vitest.config.tsin your project root (orvitest.config.jsfor JavaScript projects) - Import
defineConfigfromvitest/configand settestobject withenvironmentoption (use'node'for backend,'jsdom'for DOM testing) - Configure
includeandexcludepatterns to specify which files Vitest should scan (e.g.,**/*.test.ts,**/*.spec.ts) - Set
globals: trueif you wantdescribe,test,expectavailable without imports - Add
coverageobject withprovider: 'v8'or'istanbul'andreporter: ['text', 'json']for coverage reports - Configure
setupFilesarray to point to setup scripts that run before tests (e.g.,['./vitest.setup.ts']) - Add
testscript topackage.json:"test": "vitest"and"test:ui": "vitest --ui" - Run
npm testto verify Vitest discovers and executes tests
Code
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
import path from 'path'
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
test: {
// Test environment: 'node', 'jsdom', 'happy-dom', or 'edge-runtime'
environment: 'jsdom',
// Auto-import test globals (describe, test, expect, etc.)
globals: true,
// Setup files that run before test suite
setupFiles: ['./vitest.setup.ts'],
// File patterns to include in test discovery
include: ['src/**/*.{test,spec}.{js,ts,jsx,tsx}'],
exclude: ['node_modules', 'dist'],
// Coverage configuration
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: [
'node_modules/',
'dist/',
'**/*.spec.ts',
'**/*.test.ts',
],
lines: 80,
functions: 80,
branches:
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Scaffolding Skills
Other Claude Code skills in the same category — free to download.
Next.js Starter
Scaffold Next.js project with common setup
Express Starter
Scaffold Express.js project with structure
React Starter
Scaffold React project with Vite
TypeScript Config
Set up TypeScript configuration
ESLint Config
Configure ESLint with custom rules
Prettier Config
Set up Prettier configuration
Monorepo Setup
Set up monorepo with Turborepo/Nx
Jest Config
Configure Jest testing framework
Want a Scaffolding skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.