[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(vitest): correctly rerun test files on change if server was restarted (#4871)

authored by

Vladimir and committed by
GitHub
(Jan 4, 2024, 5:37 PM +0100) 6088b372 e12a5a36

+15 -2
+15 -2
packages/vitest/src/node/core.ts
··· 126 126 const serverRestart = server.restart 127 127 server.restart = async (...args) => { 128 128 await Promise.all(this._onRestartListeners.map(fn => fn())) 129 - return await serverRestart(...args) 129 + await serverRestart(...args) 130 + // watcher is recreated on restart 131 + this.unregisterWatcher() 132 + this.registerWatcher() 130 133 } 131 134 132 135 // since we set `server.hmr: false`, Vite does not auto restart itself ··· 136 139 if (isConfig) { 137 140 await Promise.all(this._onRestartListeners.map(fn => fn('config'))) 138 141 await serverRestart() 142 + // watcher is recreated on restart 143 + this.unregisterWatcher() 144 + this.registerWatcher() 139 145 } 140 146 }) 141 147 } ··· 729 735 } 730 736 731 737 const projects = this.getModuleProjects(id) 732 - if (!projects.length) 738 + if (!projects.length) { 739 + // if there are no modules it's possible that server was restarted 740 + // we don't have information about importers anymore, so let's check if the file is a test file at least 741 + if (this.state.filesMap.has(id) || this.projects.some(project => project.isTestFile(id))) { 742 + this.changedTests.add(id) 743 + return [id] 744 + } 733 745 return [] 746 + } 734 747 735 748 const files: string[] = [] 736 749