From c66e335b9ae3d6a0ac22a7ecf19e272c33095cf7 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 27 Jan 2023 12:33:44 +0100 Subject: [PATCH] feat: allow `config` option to be false (#2749) --- packages/vitest/src/node/cache/index.ts | 14 +++++++++----- packages/vitest/src/node/create.ts | 8 +++++--- packages/vitest/src/types/config.ts | 4 +++- 3 files changed, 17 insertions(+), 9 deletions(-) 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