vitest-dev / vitest-dev/vitest
Monorepo Vitest setup with shared config and projects
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 94
Description
Describe the bug
Hi Vitest team 👋,
I’m working on a fairly large pnpm + Turborepo monorepo and I’d like to get feedback on whether my current Vitest configuration and overall approach are correct, or if I’m misusing some concepts.
Context
My monorepo contains multiple workspaces:
packages/*(CLI, API, shared configs, etc.)
I’m using a shared Vitest config package (@aoc-ts/config-vitest) that is imported by:
- each workspace
- the root of the monorepo
This allows me to:
- run all tests with a single
vitestcommand - also run them efficiently via Turborepo
Shared Vitest configuration
My shared config defines multiple projects (unit + e2e) and shared excludes:
import { configDefaults, defineConfig } from 'vitest/config';
const commonExclude = [
...configDefaults.exclude,
'**/__snapshots__/**',
'**/templates/**',
];
export const sharedConfig = defineConfig({
server: {
watch: {
ignored: commonExclude,
},
},
test: {
exclude: commonExclude,
benchmark: {
exclude: commonExclude,
},
projects: [
{
extends: true,
test: {
name: 'unit',
testTimeout: 30_000,
include: ['**/*.unit.test.ts'],
benchmark: {
include: ['**/*.unit.bench.ts'],
},
},
},
{
extends: true,
test: {
name: 'e2e',
testTimeout: 30_000,
include: ['**/*.e2e.test.ts'],
benchmark: {
include: ['**/*.e2e.bench.ts'],
},
},
},
],
},
});
Each workspace extends this shared config.
Root Vitest config (future need)
In the future, I’ll need workspace-specific setupFiles (for mocks, globals, etc.).
From what I understand, the recommended root config for a monorepo should look like this:
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
projects: ['packages/*'],
},
});
However, when I introduce this root-level projects config:
- I start seeing unexpected timeouts
- some tests behave differently compared to running Vitest directly inside a workspace
- configuration such as
testTimeoutdoes not always seem to be applied as expected
Questions
-
Is this overall approach valid?
- Shared config package
test.projectsdefined inside the shared config- Root config delegating to workspaces via
projects: ['packages/*']
-
Is it expected that defining
projectsat the root level can change timeout behavior or test execution semantics? -
For monorepos that need:
- shared defaults
- workspace-specific
setupFiles - compatibility with Turborepo
what is the recommended Vitest architecture today?
-
Should:
test.projectslive only at the root?- or only inside workspace configs?
- or is nesting/combining them discouraged?
Goal
My goal is to have:
- one command to run all tests
- predictable timeouts and test behavior
- flexibility to add setupFiles per workspace
- no duplication of config across packages
Any guidance, best practices, or pointers to documentation/examples would be greatly appreciated.
Thanks a lot for your work on Vitest and for your help!
Reproduction
my monorepo : https://gitlab.com/Robin-Ln/aoc-ts
System Info
System:
OS: macOS 15.5
CPU: (10) arm64 Apple M1 Pro
Memory: 89.73 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 25.2.1 - /Users/rlouarn/.nvm/versions/node/v25.2.1/bin/node
npm: 11.6.2 - /Users/rlouarn/.nvm/versions/node/v25.2.1/bin/npm
pnpm: 10.27.0 - /Users/rlouarn/Library/pnpm/pnpm
Browsers:
Chrome: 143.0.7499.193
Safari: 18.5
npmPackages:
vitest: catalog: => 4.0.16
Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the shared Vitest configuration, the root projects configuration, and the workspace configs described in the report; reproduce the timeout difference using the linked monorepo. Compare direct workspace runs with root and Turborepo runs, then document the configuration semantics and a supported architecture for shared defaults, workspace setupFiles, and predictable timeouts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing-qa, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100