Vitest Setup
Detect the project type, generate the right Vitest configuration, and produce working test infrastructure. Not a reference card — this skill creates files.
Workflow
- Detect — scan the project to determine type and existing setup
- Configure — generate vitest.config.ts tailored to the environment
- Scaffold — create test setup, utilities, and a sample test
- Wire up — add package.json scripts and TypeScript config
Step 1: Detect Project Type
Read these files to determine the project:
Classify as one of:
If a vite.config.ts already exists, extend it rather than creating a separate vitest.config.ts — Vitest reads Vite config natively.
Step 2: Install Dependencies
Generate the install command based on detected type:
Use the project's package manager (check for pnpm-lock.yaml, yarn.lock, bun.lockb, or package-lock.json).
Step 3: Generate vitest.config.ts
Cloudflare Workers
If the project uses the Cloudflare Vite plugin (@cloudflare/vite-plugin), integrate into the existing vite.config.ts instead:
React (Vite)
If a vite.config.ts already exists, add the test block to it rather than creating a new file.
Node / Hono API
With Coverage (add to any config)
Step 4: Generate Test Setup File
Create src/test/setup.ts (React projects only):
That single import adds all the custom matchers (toBeInTheDocument, toHaveTextContent, etc.) and registers the Vitest expect.extend automatically.
Step 5: Add TypeScript Config
Add to tsconfig.json compilerOptions:
For projects with multiple tsconfig files (e.g. tsconfig.app.json + tsconfig.node.json), add to the one that covers test files — usually the root tsconfig.json or create a tsconfig.test.json that extends it.
Step 6: Add Package.json Scripts
Don't overwrite existing scripts — merge with what's there.
Step 7: Generate Sample Test
Write one test file that demonstrates the right patterns for this specific project. Place it next to real source code, not in a separate __tests__ directory.
For a Hono API route (e.g. src/routes/health.ts):
For a React component (e.g. src/components/Button.tsx):
For a utility function (e.g. src/utils/format.ts):
Pick a real file from the project to test. Don't invent a fake module — the sample test should run immediately after setup.
Step 8: Verify
Run the tests to confirm everything works:
If it fails, diagnose and fix. Common issues:
Mocking Reference
These patterns are for writing tests after setup is complete. Include them in the sample test or a src/test/examples.test.ts if the user asks for mocking examples.
Module mocking (vi.mock)
Spy on methods (vi.spyOn)
Fake timers
Global stubs
Snapshot testing
Parameterized tests
Jest Migration
When the detected project has Jest (jest.config.*, @types/jest, ts-jest in dependencies):
- Generate the vitest.config.ts using the steps above
- Update imports in existing test files:
- Remove Jest packages:
-
Update tsconfig — replace
"types": ["jest"]with"types": ["vitest/globals"] -
Run tests and fix any remaining issues
Key replacements:
Workspace Setup (Monorepos)
For monorepo projects with multiple packages:
Each package gets its own config. The workspace file just points to them.
What This Skill Produces
After running, the project should have:
vitest.config.ts(or test block added to existing vite.config.ts)src/test/setup.ts(React projects)- Updated
tsconfig.jsonwith vitest/globals type - Updated
package.jsonwith test scripts - At least one passing sample test against real source code
- Dependencies installed
The tests should pass on first run. If they don't, fix them before finishing.


