diff --git a/packages/vitest/src/node/cache/index.ts b/packages/vitest/src/node/cache/index.ts index b947aa346ffb..88f43e9bd2e0 100644 --- a/packages/vitest/src/node/cache/index.ts +++ b/packages/vitest/src/node/cache/index.ts @@ -27,13 +27,17 @@ export class VitestCache { static async clearCache(options: CliOptions) { const root = resolve(options.root || process.cwd()) - const configPath = options.config - ? resolve(root, options.config) - : await findUp(configFiles, { cwd: root } as any) + const configPath = options.config === false + ? false + : options.config + ? resolve(root, options.config) + : await findUp(configFiles, { cwd: root } as any) - const config = await loadConfigFromFile({ command: 'serve', mode: 'test' }, configPath) + const config = configPath + ? (await loadConfigFromFile({ command: 'serve', mode: 'test' }, configPath))?.config + : undefined - const cache = config?.config.test?.cache + const cache = config?.test?.cache if (cache === false) throw new Error('Cache is disabled') diff --git a/packages/vitest/src/node/create.ts b/packages/vitest/src/node/create.ts index 707248374773..4d64cf1c1901 100644 --- a/packages/vitest/src/node/create.ts +++ b/packages/vitest/src/node/create.ts @@ -11,9 +11,11 @@ export async function createVitest(mode: VitestRunMode, options: UserConfig, vit const ctx = new Vitest(mode) const root = resolve(options.root || process.cwd()) - const configPath = options.config - ? resolve(root, options.config) - : await findUp(configFiles, { cwd: root } as any) + const configPath = options.config === false + ? false + : options.config + ? resolve(root, options.config) + : await findUp(configFiles, { cwd: root } as any) const config: ViteInlineConfig = { logLevel: 'error', diff --git a/packages/vitest/src/types/config.ts b/packages/vitest/src/types/config.ts index 9ba0879ff7aa..b01c587e6ba6 100644 --- a/packages/vitest/src/types/config.ts +++ b/packages/vitest/src/types/config.ts @@ -563,8 +563,10 @@ export interface UserConfig extends InlineConfig { * Path to the config file. * * Default resolving to `vitest.config.*`, `vite.config.*` + * + * Setting to `false` will disable config resolving. */ - config?: string | undefined + config?: string | false | undefined /** * Use happy-dom