From 30715669709898dec31270157ee2eb6acff118ee Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Wed, 15 Jan 2025 11:33:29 +0100 Subject: [PATCH] fix watch mode in Vitest 3 --- code/addons/test/src/node/vitest-manager.ts | 27 +++++++++------------ 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/code/addons/test/src/node/vitest-manager.ts b/code/addons/test/src/node/vitest-manager.ts index 217fe79729b9..01dde74e56b8 100644 --- a/code/addons/test/src/node/vitest-manager.ts +++ b/code/addons/test/src/node/vitest-manager.ts @@ -164,22 +164,17 @@ export class VitestManager { } private updateLastChanged(filepath: string) { - if (isVitest3OrLater) { - const serverMods = this.vite?.moduleGraph.getModulesByFile(filepath); - serverMods?.forEach((mod) => this.vite?.moduleGraph.invalidateModule(mod)); - } else { - const projects = this.vitest!.getModuleProjects(filepath); - projects.forEach(({ server, browser }) => { - if (server) { - const serverMods = server.moduleGraph.getModulesByFile(filepath); - serverMods?.forEach((mod) => server.moduleGraph.invalidateModule(mod)); - } - if (browser) { - const browserMods = browser.vite.moduleGraph.getModulesByFile(filepath); - browserMods?.forEach((mod) => browser.vite.moduleGraph.invalidateModule(mod)); - } - }); - } + const projects = this.vitest!.getModuleProjects(filepath); + projects.forEach(({ server, browser }) => { + if (server) { + const serverMods = server.moduleGraph.getModulesByFile(filepath); + serverMods?.forEach((mod) => server.moduleGraph.invalidateModule(mod)); + } + if (browser) { + const browserMods = browser.vite.moduleGraph.getModulesByFile(filepath); + browserMods?.forEach((mod) => browser.vite.moduleGraph.invalidateModule(mod)); + } + }); } private async fetchStories(indexUrl: string, requestStoryIds?: string[]) {