Skip to content

Commit

Permalink
fix(browser): cleanup timeout on resolve and give more information in…
Browse files Browse the repository at this point in the history
… the error
  • Loading branch information
sheremet-va committed Feb 13, 2025
1 parent accd2ed commit 8b85716
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/vitest/src/node/browser/sessions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { TestProject } from '../project'
import type { BrowserServerStateSession } from '../types/browser'
import { createDefer } from '@vitest/utils'
import { relative } from 'pathe'

export class BrowserSessions {
private sessions = new Map<string, BrowserServerStateSession>()
Expand All @@ -13,7 +14,8 @@ export class BrowserSessions {
const defer = createDefer<void>()

const timeout = setTimeout(() => {
defer.reject(new Error(`Failed to connect to the browser session "${sessionId}" within the timeout.`))
const tests = files.map(file => relative(project.config.root, file)).join('", "')
defer.reject(new Error(`Failed to connect to the browser session "${sessionId}" [${project.name}] for "${tests}" within the timeout.`))
}, project.vitest.config.browser.connectTimeout ?? 60_000).unref()

this.sessions.set(sessionId, {
Expand All @@ -25,6 +27,7 @@ export class BrowserSessions {
},
resolve: () => {
defer.resolve()
clearTimeout(timeout)
this.sessions.delete(sessionId)
},
reject: defer.reject,
Expand Down

0 comments on commit 8b85716

Please sign in to comment.