Skip to content

Commit c66e335

Browse files
authoredJan 27, 2023
feat: allow config option to be false (#2749)
1 parent ebc95ad commit c66e335

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed
 

‎packages/vitest/src/node/cache/index.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ export class VitestCache {
2727
static async clearCache(options: CliOptions) {
2828
const root = resolve(options.root || process.cwd())
2929

30-
const configPath = options.config
31-
? resolve(root, options.config)
32-
: await findUp(configFiles, { cwd: root } as any)
30+
const configPath = options.config === false
31+
? false
32+
: options.config
33+
? resolve(root, options.config)
34+
: await findUp(configFiles, { cwd: root } as any)
3335

34-
const config = await loadConfigFromFile({ command: 'serve', mode: 'test' }, configPath)
36+
const config = configPath
37+
? (await loadConfigFromFile({ command: 'serve', mode: 'test' }, configPath))?.config
38+
: undefined
3539

36-
const cache = config?.config.test?.cache
40+
const cache = config?.test?.cache
3741

3842
if (cache === false)
3943
throw new Error('Cache is disabled')

‎packages/vitest/src/node/create.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ export async function createVitest(mode: VitestRunMode, options: UserConfig, vit
1111
const ctx = new Vitest(mode)
1212
const root = resolve(options.root || process.cwd())
1313

14-
const configPath = options.config
15-
? resolve(root, options.config)
16-
: await findUp(configFiles, { cwd: root } as any)
14+
const configPath = options.config === false
15+
? false
16+
: options.config
17+
? resolve(root, options.config)
18+
: await findUp(configFiles, { cwd: root } as any)
1719

1820
const config: ViteInlineConfig = {
1921
logLevel: 'error',

‎packages/vitest/src/types/config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,10 @@ export interface UserConfig extends InlineConfig {
563563
* Path to the config file.
564564
*
565565
* Default resolving to `vitest.config.*`, `vite.config.*`
566+
*
567+
* Setting to `false` will disable config resolving.
566568
*/
567-
config?: string | undefined
569+
config?: string | false | undefined
568570

569571
/**
570572
* Use happy-dom

0 commit comments

Comments
 (0)
Please sign in to comment.