From 6ce3ed7f91cdec240e6c442965ac1a1f5223b4b6 Mon Sep 17 00:00:00 2001 From: Robin Mehner Date: Mon, 21 Nov 2022 16:52:04 +0100 Subject: [PATCH] fix(cli): don't override config by setting cli options to undefined (#2330) This has been introduced by #2180. The change there will *always* set argv.dir, no matter if it's been there before or not. When it's not there, it will set it to undefined, which then will lead to vitest using the root as fallback instead of the config set in the config file, since CLI options override config options. In our case, this config was essentially ignored since 0.24.4. ```js import { defineConfig } from "vite" export default defineConfig({ test: { dir: "spec/javascript" } }) ``` with the only workaround of providing `dir` via CLI option. --- packages/vitest/src/node/cli.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/vitest/src/node/cli.ts b/packages/vitest/src/node/cli.ts index 7d2edb7e9d33..724ffd1c13d6 100644 --- a/packages/vitest/src/node/cli.ts +++ b/packages/vitest/src/node/cli.ts @@ -103,9 +103,15 @@ async function typecheck(cliFilters: string[] = [], options: CliOptions = {}) { } function normalizeOptions(argv: CliOptions): CliOptions { - argv.root = argv.root && normalize(argv.root) - argv.config = argv.config && normalize(argv.config) - argv.dir = argv.dir && normalize(argv.dir) + if (argv.root) + argv.root = normalize(argv.root) + + if (argv.config) + argv.config = normalize(argv.config) + + if (argv.dir) + argv.dir = normalize(argv.dir) + return argv }