diff --git a/packages/browser/src/node/pool.ts b/packages/browser/src/node/pool.ts index c0bc9f0f8828..bd7399a42dee 100644 --- a/packages/browser/src/node/pool.ts +++ b/packages/browser/src/node/pool.ts @@ -86,8 +86,13 @@ export function createBrowserPool(ctx: Vitest): ProcessPool { [...files.map(f => relative(project.config.root, f))].join(', '), ) const promise = waitForTests(method, contextId, project, files) - promises.push(promise) - orchestrator.createTesters(files) + const tester = orchestrator.createTesters(files).catch((error) => { + if (error instanceof Error && error.message.startsWith('[birpc] rpc is closed')) { + return + } + return Promise.reject(error) + }) + promises.push(promise, tester) } else { const contextId = crypto.randomUUID() @@ -156,6 +161,11 @@ export function createBrowserPool(ctx: Vitest): ProcessPool { async close() { await Promise.all([...providers].map(provider => provider.close())) providers.clear() + ctx.resolvedProjects.forEach((project) => { + project.browser?.state.orchestrators.forEach((orchestrator) => { + orchestrator.$close() + }) + }) }, runTests: files => runWorkspaceTests('run', files), collectTests: files => runWorkspaceTests('collect', files), diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index d1eb91d4c6f2..0d885bd58fe9 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -77,7 +77,8 @@ export class Vitest { private coreWorkspaceProject!: WorkspaceProject - private resolvedProjects: WorkspaceProject[] = [] + /** @private */ + public resolvedProjects: WorkspaceProject[] = [] public projects: WorkspaceProject[] = [] public distPath = distDir diff --git a/packages/vitest/src/node/types/browser.ts b/packages/vitest/src/node/types/browser.ts index 3d607c6dae47..243fdfcbc614 100644 --- a/packages/vitest/src/node/types/browser.ts +++ b/packages/vitest/src/node/types/browser.ts @@ -194,6 +194,7 @@ export interface BrowserServerStateContext { export interface BrowserOrchestrator { createTesters: (files: string[]) => Promise onCancel: (reason: CancelReason) => Promise + $close: () => void } export interface BrowserServerState {