Skip to content

Commit 4d277d8

Browse files
authoredFeb 25, 2023
fix: reload changed configuration file on watch mode (#2889)
1 parent e165216 commit 4d277d8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
 

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export class Vitest {
6262
this.restartsCount += 1
6363
this.pool?.close()
6464
this.pool = undefined
65+
this.coverageProvider = undefined
66+
this.runningPromise = undefined
6567

6668
const resolved = resolveConfig(this.mode, options, server.config)
6769

@@ -110,8 +112,6 @@ export class Vitest {
110112
? await createBenchmarkReporters(toArray(resolved.benchmark?.reporters), this.runner)
111113
: await createReporters(resolved.reporters, this.runner)
112114

113-
this.runningPromise = undefined
114-
115115
this.cache.results.setConfig(resolved.root, resolved.cache)
116116
try {
117117
await this.cache.results.readFromCache()

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

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { CSSEnablerPlugin } from './cssEnabler'
1414
import { CoverageTransform } from './coverageTransform'
1515

1616
export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('test')): Promise<VitePlugin[]> {
17+
const userConfig = deepMerge({}, options) as UserConfig
18+
1719
const getRoot = () => ctx.config?.root || options.root || process.cwd()
1820

1921
async function UIPlugin() {
@@ -34,6 +36,12 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
3436
this.meta.watchMode = false
3537
},
3638
async config(viteConfig: any) {
39+
if (options.watch) {
40+
// Earlier runs have overwritten values of the `options`.
41+
// Reset it back to initial user config before setting up the server again.
42+
options = deepMerge({}, userConfig) as UserConfig
43+
}
44+
3745
// preliminary merge of options to be able to create server options for vite
3846
// however to allow vitest plugins to modify vitest config values
3947
// this is repeated in configResolved where the config is final

0 commit comments

Comments
 (0)
Please sign in to comment.