diff --git a/docs/guide/projects.md b/docs/guide/projects.md index 56216cc1a69b..ae68f4076870 100644 --- a/docs/guide/projects.md +++ b/docs/guide/projects.md @@ -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..config.*` / `vite..config.*`, where `` 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` diff --git a/packages/vitest/src/node/projects/resolveProjects.ts b/packages/vitest/src/node/projects/resolveProjects.ts index 98387ab3c449..bd69651a5510 100644 --- a/packages/vitest/src/node/projects/resolveProjects.ts +++ b/packages/vitest/src/node/projects/resolveProjects.ts @@ -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, diff --git a/test/cli/test/projects.test.ts b/test/cli/test/projects.test.ts index 4ca11b2e5fbf..0495ca4a1c48 100644 --- a/test/cli/test/projects.test.ts +++ b/test/cli/test/projects.test.ts @@ -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': {},