[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: rerun tests when project's setup file is changed (#8097)

authored by

Vladimir and committed by
GitHub
(Jun 5, 2025, 6:40 PM +0200) 0f335066 7ddcd336

+67 -2
-1
test/workspaces/vitest.config.ts
··· 23 23 globalConfigValue: true, 24 24 }, 25 25 projects: [ 26 - 27 26 'space_2', 28 27 './space_*/vitest.config.ts', 29 28 './space_1/*.config.ts',
+42 -1
test/watch/test/workspaces.test.ts
··· 3 3 import { dirname, resolve } from 'pathe' 4 4 import { afterAll, afterEach, expect, it } from 'vitest' 5 5 6 - import { runVitestCli } from '../../test-utils' 6 + import { runInlineTests, runVitestCli } from '../../test-utils' 7 7 8 8 const file = fileURLToPath(import.meta.url) 9 9 const dir = dirname(file) ··· 124 124 expect(vitest.stdout).not.include('|space_2|') 125 125 expect(vitest.stdout).not.include('|node|') 126 126 expect(vitest.stdout).not.include('|happy-dom|') 127 + }) 128 + 129 + it('editing a setup file inside the project reruns tests', async () => { 130 + const { fs, vitest } = await runInlineTests({ 131 + 'setupFile.js': '', 132 + 'project-1/basic.test.js': `test("[p1] reruns")`, 133 + 'project-2/basic.test.js': `test("[p2] doesn\'t rerun")`, 134 + 'vitest.config.js': { 135 + test: { 136 + projects: [ 137 + { 138 + test: { 139 + name: 'p1', 140 + include: ['./project-1/basic.test.js'], 141 + setupFiles: ['./setupFile.js'], 142 + globals: true, 143 + }, 144 + }, 145 + { 146 + test: { 147 + name: 'p2', 148 + include: ['./project-2/basic.test.js'], 149 + globals: true, 150 + }, 151 + }, 152 + ], 153 + }, 154 + }, 155 + }, { watch: true }) 156 + 157 + await vitest.waitForStdout('Waiting for file changes') 158 + expect(vitest.stdout).toContain('[p1] reruns') 159 + expect(vitest.stdout).toContain('[p2] doesn\'t rerun') 160 + 161 + fs.editFile('./setupFile.js', () => '// ---edit') 162 + 163 + vitest.resetOutput() 164 + await vitest.waitForStdout('Test Files 1 passed') 165 + 166 + expect(vitest.stdout).toContain('[p1] reruns') 167 + expect(vitest.stdout).not.toContain('[p2] doesn\'t rerun') 127 168 })
+25
packages/vitest/src/node/watcher.ts
··· 140 140 } 141 141 } 142 142 143 + private handleSetupFile(filepath: string) { 144 + let isSetupFile: boolean = false 145 + 146 + this.vitest.projects.forEach((project) => { 147 + if (!project.config.setupFiles.includes(filepath)) { 148 + return 149 + } 150 + 151 + this.vitest.state.filesMap.forEach((files) => { 152 + files.forEach((file) => { 153 + if (file.projectName === project.name) { 154 + isSetupFile = true 155 + this.changedTests.add(file.filepath) 156 + } 157 + }) 158 + }) 159 + }) 160 + 161 + return isSetupFile 162 + } 163 + 143 164 /** 144 165 * @returns A value indicating whether rerun is needed (changedTests was mutated) 145 166 */ ··· 150 171 151 172 if (pm.isMatch(filepath, this.vitest.config.forceRerunTriggers)) { 152 173 this.vitest.state.getFilepaths().forEach(file => this.changedTests.add(file)) 174 + return true 175 + } 176 + 177 + if (this.handleSetupFile(filepath)) { 153 178 return true 154 179 } 155 180