diff --git a/packages/browser/src/node/plugin.ts b/packages/browser/src/node/plugin.ts index 524fb9bf3307..a80bdfa13554 100644 --- a/packages/browser/src/node/plugin.ts +++ b/packages/browser/src/node/plugin.ts @@ -8,7 +8,6 @@ import type { WorkspaceProject } from 'vitest/node' import { getFilePoolName, resolveApiServerConfig, resolveFsAllow, distDir as vitestDist } from 'vitest/node' import { type Plugin, coverageConfigDefaults } from 'vitest/config' import { toArray } from '@vitest/utils' -import { defaultBrowserPort } from 'vitest/config' import { dynamicImportPlugin } from '@vitest/mocker/node' import MagicString from 'magic-string' import BrowserContext from './plugins/pluginContext' @@ -329,14 +328,16 @@ export default (browserServer: BrowserServer, base = '/'): Plugin[] => { viteConfig.esbuild.legalComments = 'inline' } + const defaultPort = project.ctx._browserLastPort++ + const api = resolveApiServerConfig( viteConfig.test?.browser || {}, - defaultBrowserPort, + defaultPort, ) viteConfig.server = { ...viteConfig.server, - port: defaultBrowserPort, + port: defaultPort, ...api, middlewareMode: false, open: false, diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index efa2f74db554..745335ad30b2 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -12,7 +12,7 @@ import { noop, slash, toArray } from '@vitest/utils' import { getTasks, hasFailed } from '@vitest/runner/utils' import { version } from '../../package.json' with { type: 'json' } import { getCoverageProvider } from '../integrations/coverage' -import { workspacesFiles as workspaceFiles } from '../constants' +import { defaultBrowserPort, workspacesFiles as workspaceFiles } from '../constants' import { WebSocketReporter } from '../api/setup' import type { SerializedCoverageConfig } from '../runtime/config' import type { ArgumentsType, OnServerRestartHandler, ProvidedContext, UserConsoleLog } from '../types/general' @@ -87,6 +87,9 @@ export class Vitest { /** @deprecated use `_cachedSpecs` */ projectTestFiles = this._cachedSpecs + /** @private */ + public _browserLastPort = defaultBrowserPort + constructor( public readonly mode: VitestRunMode, options: VitestOptions = {},