Migrate from Vitest 2.x/3.x to 4.x with pool options, coverage config, workspace to projects, and browser mode updates. Use when upgrading Vitest versions or encountering deprecated patterns.
Migrates Vitest configs from 2.x/3.x to 4.x by updating pool options, coverage settings, workspace to projects, and browser mode imports. Use when upgrading Vitest versions or encountering deprecated configuration patterns.
/plugin marketplace add djankies/claude-configs/plugin install vitest-4@claude-configsThis skill is limited to using the following tools:
references/migration-tables.mdreferences/migration-workflow.mdThis skill guides migration from Vitest 2.x/3.x to 4.x, focusing on breaking changes and deprecated patterns.
Vitest 4.0 introduces breaking changes in:
Before (Vitest 3.x):
export default defineConfig({
test: {
maxThreads: 4,
singleThread: true,
},
});
After (Vitest 4.x):
export default defineConfig({
test: {
maxWorkers: 4,
maxWorkers: 1,
isolate: false,
},
});
Before (Vitest 3.x):
coverage: {
provider: 'v8',
all: true,
}
After (Vitest 4.x):
coverage: {
provider: 'v8',
include: ['src/**/*.{ts,tsx}'],
}
Before (Vitest 3.x):
import { defineWorkspace } from 'vitest/config';
export default defineWorkspace([
{ test: { name: 'unit' } },
]);
After (Vitest 4.x):
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
projects: [
{ test: { name: 'unit' } },
],
},
});
Before (Vitest 3.x):
browser: {
enabled: true,
name: 'chromium',
provider: 'playwright',
}
After (Vitest 4.x):
import { playwright } from '@vitest/browser-playwright';
browser: {
enabled: true,
provider: playwright(),
instances: [{ browser: 'chromium' }],
}
Import updates:
import { page } from 'vitest/browser';
Before (Vitest 3.x):
deps: {
inline: ['vue'],
}
After (Vitest 4.x):
server: {
deps: {
inline: ['vue'],
},
}
For detailed migration tables covering all options, see references/migration-tables.md
npm install -D vitest@latest
maxThreads/maxForks with maxWorkerscoverage.include patternsdefineWorkspace with projectsdeps.* to server.deps.*grep -r "@vitest/browser/context" . --include="*.ts"
Replace with:
import { page, userEvent } from 'vitest/browser';
If using browser mode:
npm install -D @vitest/browser-playwright
vitest --run
Check for deprecation warnings.
vitest --coverage
For complete migration workflow with troubleshooting, see references/migration-workflow.md
vitest to 4.xmaxThreads/maxForks with maxWorkerscoverage.include patternsdefineWorkspace with projectsdeps.* to server.deps.*@vitest/browser/context to vitest/browservitest/execute importsVITE_NODE_DEPS_MODULE_DIRECTORIES with VITEST_MODULE_DIRECTORIESSolution: Replace with maxWorkers
Solution: Add explicit coverage.include patterns
Solution: Replace defineWorkspace with defineConfig and projects
Solution: Install provider package and update imports
Solution: Move to server.deps.inline
For detailed troubleshooting, see references/migration-workflow.md
Returns vi.fn() instead of spy in Vitest 4.x
Starts at 1 instead of 0 (matching Jest)
No longer affects automocks
Before (Vitest 3.x):
reporters: ['basic']
After (Vitest 4.x):
reporters: ['default'],
summary: false
Before:
VITE_NODE_DEPS_MODULE_DIRECTORIES=/path vitest
After:
VITEST_MODULE_DIRECTORIES=/path vitest
Vitest 3.x: Excluded many directories by default
Vitest 4.x: Only excludes node_modules and .git
Add explicit excludes if needed:
coverage: {
include: ['src/**/*.ts'],
exclude: [
'**/node_modules/**',
'**/dist/**',
'**/*.test.ts',
],
}
For detailed migration information:
For new configuration patterns, see @vitest-4/skills/configuring-vitest-4
For browser mode setup, see @vitest-4/skills/using-browser-mode
For complete API reference, see @vitest-4/knowledge/vitest-4-comprehensive.md
Master authentication and authorization patterns including JWT, OAuth2, session management, and RBAC to build secure, scalable access control systems. Use when implementing auth systems, securing APIs, or debugging security issues.