Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reload changed configuration file on watch mode #2889

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why options.watch? watch mode can be configured in the config

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options.watch is set to true here even if it is only given in the config file. On first run it corresponds the CLI flags, but on second run it's overwritten by this plugin.

// 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