Skip to content

Commit

Permalink
feat: allow config option to be false (#2749)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 27, 2023
1 parent ebc95ad commit c66e335
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
14 changes: 9 additions & 5 deletions packages/vitest/src/node/cache/index.ts
Expand Up @@ -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')
Expand Down
8 changes: 5 additions & 3 deletions packages/vitest/src/node/create.ts
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion packages/vitest/src/types/config.ts
Expand Up @@ -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
Expand Down

0 comments on commit c66e335

Please sign in to comment.