From 9967645ab7ade16a2b2495c7ee0277d180f866f1 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 11 Jan 2023 17:28:49 +0100 Subject: [PATCH] fix: always update last HMR ms on a module --- packages/vitest/src/node/core.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 74104d8df29d..b5392e6ab78f 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -403,9 +403,6 @@ export class Vitest { private _rerunTimer: any private async scheduleRerun(triggerId: string) { - const mod = this.server.moduleGraph.getModuleById(triggerId) - if (mod) - mod.lastHMRTimestamp = Date.now() const currentCount = this.restartsCount clearTimeout(this._rerunTimer) await this.runningPromise @@ -447,8 +444,15 @@ export class Vitest { private unregisterWatcher = noop private registerWatcher() { + const updateLastChanged = (id: string) => { + const mod = this.server.moduleGraph.getModuleById(id) + if (mod) + mod.lastHMRTimestamp = Date.now() + } + const onChange = (id: string) => { id = slash(id) + updateLastChanged(id) const needsRerun = this.handleFileChanged(id) if (needsRerun) this.scheduleRerun(id) @@ -467,6 +471,7 @@ export class Vitest { } const onAdd = async (id: string) => { id = slash(id) + updateLastChanged(id) if (await this.isTargetFile(id)) { this.changedTests.add(id) await this.cache.stats.updateStats(id)