Skip to content

Commit

Permalink
fix: reload changed configuration file on watch mode (#2889)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Feb 25, 2023
1 parent e165216 commit 4d277d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions packages/vitest/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { CSSEnablerPlugin } from './cssEnabler'
import { CoverageTransform } from './coverageTransform'

export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('test')): Promise<VitePlugin[]> {
const userConfig = deepMerge({}, options) as UserConfig

const getRoot = () => ctx.config?.root || options.root || process.cwd()

async function UIPlugin() {
Expand All @@ -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
Expand Down

0 comments on commit 4d277d8

Please sign in to comment.