Configuring vitest to use singleFork for some files, not others #6438
-
I have a suite of tests that come from a legacy Jest setup that used import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
pool: 'forks',
poolOptions: {
forks: {
singleFork: true,
}
},
sequence: {
hooks: 'list',
},
},
}); This would be the default config, but for some known files I want to actually forego the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Answering myself to help others. Create a file import { defineWorkspace } from 'vitest/config'
const PARALLEL_CAPABLE_TEST_FILES = [
'test/something.unit.test.ts',
'test/somethingElse.unit.test.ts',
];
export default defineWorkspace([
{
extends: './vitest.config.ts',
test: {
name: 'parallel',
include: PARALLEL_CAPABLE_TEST_FILES,
},
},
{
extends: './vitest.config.ts',
test: {
name: 'sequential',
include: ['test/**/*.test.ts'],
exclude: PARALLEL_CAPABLE_TEST_FILES,
poolOptions: {
forks: {
singleFork: true,
}
},
},
},
]); You need to remove the Then run the parallel tests only with (same for npx vitest --project parallel |
Beta Was this translation helpful? Give feedback.
You can also define the
singleFork
in the workspace file. Then you can run all tests with a singlevitest
command.Here I have 4 tests:
vitest-workspace-singlefork.mov