Run Vitest with a different config per folder
Give each folder its own Vitest config with the projects option, so unit and integration tests get different timeouts and setup in one run.
Fast unit tests and slow database tests want different timeouts, setup files and environments. Instead of two commands, declare two projects that point at their own configs.
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
projects: ['tests/unit', 'tests/integration'],
},
});import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
name: 'integration',
include: ['**/*.test.js'],
testTimeout: 30_000,
setupFiles: ['./setup-db.js'],
},
});import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
name: 'unit',
include: ['**/*.test.js'],
testTimeout: 2_000,
},
}); ✓ |unit| tests/unit/cart.test.js (3 tests)
✓ |integration| tests/integration/orders.test.js (2 tests)Each folder in projects is searched for a config file, and its options apply only to that project. Run one alone with vitest --project integration. This needs Vitest 3.2 or newer, where projects replaced the separate workspace file, per the Vitest projects guide.
Include paths inside a project config are relative to that config's folder, not to the repository root, which is a common source of "no test files found".