From 4d277d8d1dc5d9e663252d604ba54765e50dc8d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Sat, 25 Feb 2023 10:06:02 +0200 Subject: [PATCH] fix: reload changed configuration file on watch mode (#2889) --- packages/vitest/src/node/core.ts | 4 ++-- packages/vitest/src/node/plugins/index.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 03ed78760d6c..32c7fe7dd223 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -62,6 +62,8 @@ export class Vitest { this.restartsCount += 1 this.pool?.close() this.pool = undefined + this.coverageProvider = undefined + this.runningPromise = undefined const resolved = resolveConfig(this.mode, options, server.config) @@ -110,8 +112,6 @@ export class Vitest { ? await createBenchmarkReporters(toArray(resolved.benchmark?.reporters), this.runner) : await createReporters(resolved.reporters, this.runner) - this.runningPromise = undefined - this.cache.results.setConfig(resolved.root, resolved.cache) try { await this.cache.results.readFromCache() diff --git a/packages/vitest/src/node/plugins/index.ts b/packages/vitest/src/node/plugins/index.ts index 15bf1f619a19..a8a4e9045c9e 100644 --- a/packages/vitest/src/node/plugins/index.ts +++ b/packages/vitest/src/node/plugins/index.ts @@ -14,6 +14,8 @@ import { CSSEnablerPlugin } from './cssEnabler' import { CoverageTransform } from './coverageTransform' export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('test')): Promise { + const userConfig = deepMerge({}, options) as UserConfig + const getRoot = () => ctx.config?.root || options.root || process.cwd() async function UIPlugin() { @@ -34,6 +36,12 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t this.meta.watchMode = false }, async config(viteConfig: any) { + if (options.watch) { + // Earlier runs have overwritten values of the `options`. + // Reset it back to initial user config before setting up the server again. + options = deepMerge({}, userConfig) as UserConfig + } + // preliminary merge of options to be able to create server options for vite // however to allow vitest plugins to modify vitest config values // this is repeated in configResolved where the config is final