Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/guide/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ export default defineConfig({
})
```

Vitest will treat every folder in `packages` as a separate project even if it doesn't have a config file inside. If the glob pattern matches a file, it will validate that the name starts with `vitest.config`/`vite.config` or matches `(vite|vitest).*.config.*` pattern to ensure it's a Vitest configuration file. For example, these config files are valid:
Vitest will treat every folder in `packages` as a separate project even if it doesn't have a config file inside. If a project entry resolves to a file (either from a glob pattern or a direct file path), Vitest will validate that the name either:

- starts with `vitest.config` or `vite.config` (for example, `vitest.config.unit.ts`)
- or matches `vitest.<name>.config.*` / `vite.<name>.config.*`, where `<name>` can contain letters, numbers, `_`, and `-`

For example, these config files are valid:

- `vitest.config.ts`
- `vite.config.js`
- `vitest.unit.config.ts`
- `vitest.e2e-node.config.ts`
- `vite.e2e.config.js`
- `vitest.config.unit.js`
- `vite.config.e2e.js`
Expand Down
3 changes: 2 additions & 1 deletion packages/vitest/src/node/projects/resolveProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { initializeProject, TestProject } from '../project'
// vite.config.*
// vitest.unit.config.*
// vite.unit.config.*
const CONFIG_REGEXP = /^vite(?:st)?(?:\.\w+)?\.config\./
// vitest.unit-test.config.*
const CONFIG_REGEXP = /^vite(?:st)?(?:\.[\w-]+)?\.config\./

export async function resolveProjects(
vitest: Vitest,
Expand Down
28 changes: 28 additions & 0 deletions test/cli/test/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,34 @@ describe('the config file names', () => {
expect(exitCode).toBe(0)
})

it('[glob] the name has "unit-test" (with hyphen) between "vitest" and "config" and works', async () => {
const { exitCode } = await runInlineTests({
'vitest.unit-test.config.js': {},
'vitest.config.js': {
test: {
passWithNoTests: true,
projects: ['./vitest.*.config.js'],
},
},
})

expect(exitCode).toBe(0)
})

it('[file] the name has "unit-test" (with hyphen) between "vitest" and "config" and works', async () => {
const { exitCode } = await runInlineTests({
'vitest.unit-test.config.js': {},
'vitest.config.js': {
test: {
passWithNoTests: true,
projects: ['./vitest.unit-test.config.js'],
},
},
})

expect(exitCode).toBe(0)
})

it('[file] the name does not start with "vite"/"vitest" and throws an error', async () => {
const { stderr } = await runInlineTests({
'unit.config.js': {},
Expand Down
Loading