[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.

chore: update preview provider re-run logic

userquin (Nov 9, 2025, 5:39 PM +0100) 60a80908 da6093b4

+21 -19
+21 -19
packages/vitest/src/node/pools/browser.ts
··· 30 30 31 31 const projectPools = new WeakMap<TestProject, BrowserPool>() 32 32 33 - const ensurePool = (project: TestProject): [existing: boolean, pool: BrowserPool] => { 33 + const ensurePool = (project: TestProject): [isNew: boolean, pool: BrowserPool] => { 34 34 if (projectPools.has(project)) { 35 - return [true, projectPools.get(project)!] 35 + return [false, projectPools.get(project)!] 36 36 } 37 37 38 38 debug?.('creating pool for project %s', project.name) ··· 55 55 pool.cancel() 56 56 }) 57 57 58 - return [false, pool] 58 + return [true, pool] 59 59 } 60 60 61 61 const runWorkspaceTests = async (method: 'run' | 'collect', specs: TestSpecification[]) => { ··· 87 87 88 88 debug?.('provider is ready for %s project', project.name) 89 89 90 - const [existing, pool] = ensurePool(project) 91 - // eager session creation and registration: don't block execution 90 + const [isNew, pool] = ensurePool(project) 92 91 vitest.state.clearFiles(project, files.map(f => f.filepath)) 93 92 providers.add(project.browser!.provider) 94 93 95 - const prepareSession: Promise<void> | undefined = project.browser!.provider.name === 'preview' 96 - ? !existing ? pool.prepareSession() : undefined // <== DON'T RECREATE THE SESSION => Vitest will hang 94 + // eager session creation and registration when using preview provider and pool created: 95 + // - DON'T RECREATE THE SESSION => Vitest will hang 96 + const prepareSession: Promise<void> | undefined = project.browser!.provider.name === 'preview' && isNew 97 + ? pool.prepareSession() 97 98 : undefined 98 99 99 100 return { ··· 239 240 240 241 this._queue.push(...files) 241 242 242 - const testRun = this.readySessions.size > 0 && this._queue.length > 0 243 - 244 - this.readySessions.forEach((sessionId) => { 245 - if (this._queue.length) { 246 - this.readySessions.delete(sessionId) 247 - this.runNextTest(method, sessionId) 248 - } 249 - }) 250 - 251 243 if (this.project.browser!.provider.name !== 'preview' && this.orchestrators.size >= this.options.maxWorkers) { 252 244 debug?.('all orchestrators are ready, not creating more') 253 245 return this._promise 254 246 } 255 247 256 248 if (this.project.browser!.provider.name === 'preview') { 257 - if (testRun) { 258 - return this._promise 259 - } 260 249 const sessionId = this.project.vitest._browserSessions.findSessionByBrowser(this.project) 261 250 if (sessionId) { 251 + // readySessions should have only the sessionId 252 + if (this.readySessions.size > 0 && this._queue.length > 0) { 253 + this.readySessions.delete(sessionId) 254 + this.runNextTest(method, sessionId) 255 + return this._promise 256 + } 262 257 this.runNextTest(method, sessionId) 263 258 debug?.('all sessions are created') 264 259 return this._promise ··· 267 262 this.cancel() 268 263 return this._promise 269 264 } 265 + 266 + this.readySessions.forEach((sessionId) => { 267 + if (this._queue.length) { 268 + this.readySessions.delete(sessionId) 269 + this.runNextTest(method, sessionId) 270 + } 271 + }) 270 272 271 273 // open the minimum amount of tabs 272 274 // if there is only 1 file running, we don't need 8 tabs running