From a5396925db8268b6c8fc6fe79d9ca529c1325739 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Wed, 15 Jan 2025 10:52:12 +0100 Subject: [PATCH] Fix optional chaining for Vitest compatibility checks --- code/addons/test/src/node/vitest-manager.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/addons/test/src/node/vitest-manager.ts b/code/addons/test/src/node/vitest-manager.ts index 284a2b47fa0..217fe79729b 100644 --- a/code/addons/test/src/node/vitest-manager.ts +++ b/code/addons/test/src/node/vitest-manager.ts @@ -165,8 +165,8 @@ export class VitestManager { private updateLastChanged(filepath: string) { if (isVitest3OrLater) { - const serverMods = this.vite.moduleGraph.getModulesByFile(filepath); - serverMods?.forEach((mod) => this.vite.moduleGraph.invalidateModule(mod)); + 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 }) => { @@ -217,7 +217,7 @@ export class VitestManager { private get vite() { // TODO: vitest.server is a Vitest < 3.0.0 API. Remove as soon as we don't support < 3.0.0 anymore. - return isVitest3OrLater ? this.vitest!.vite : this.vitest!.server; + return isVitest3OrLater ? this.vitest?.vite : this.vitest?.server; } async runFiles(specifications: TestSpecification[], allTestsRun?: boolean) { @@ -403,7 +403,7 @@ export class VitestManager { async registerVitestConfigListener() { this.vite?.watcher.on('change', async (file) => { file = normalize(file); - const isConfig = file === this.vitest?.server.config.configFile; + const isConfig = file === this.vite?.config.configFile; if (isConfig) { log('Restarting Vitest due to config change'); await this.closeVitest();