Skip to content

Commit

Permalink
fix(browser): increment browser port automatically if there are sever…
Browse files Browse the repository at this point in the history
…al projects with browser.enabled
  • Loading branch information
sheremet-va committed Oct 15, 2024
1 parent 7a375cd commit 3736d5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/browser/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -87,6 +87,9 @@ export class Vitest {
/** @deprecated use `_cachedSpecs` */
projectTestFiles = this._cachedSpecs

/** @private */
public _browserLastPort = defaultBrowserPort

constructor(
public readonly mode: VitestRunMode,
options: VitestOptions = {},
Expand Down

0 comments on commit 3736d5c

Please sign in to comment.