diff --git a/docs/config/index.md b/docs/config/index.md index e9df0fc60..0080c8937 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -1646,7 +1646,7 @@ Run every test in a separate iframe. - **Default:** `63315` - **CLI:** `--browser.api=63315`, `--browser.api.port=1234, --browser.api.host=example.com` -Configure options for Vite server that serves code in the browser. Does not affect [`test.api`](#api) option. +Configure options for Vite server that serves code in the browser. Does not affect [`test.api`](#api) option. By default, Vitest assigns port `63315` to avoid conflicts with the development server, allowing you to run both in parallel. #### browser.provider diff --git a/docs/guide/browser/index.md b/docs/guide/browser/index.md index 5eacddc8b..14dc37749 100644 --- a/docs/guide/browser/index.md +++ b/docs/guide/browser/index.md @@ -105,6 +105,10 @@ export default defineConfig({ }) ``` +::: info +Vitest assigns port `63315` to avoid conflicts with the development server, allowing you to run both in parallel. You can change that with the [`browser.api`](/config/#browser-api) option. +::: + If you have not used Vite before, make sure you have your framework's plugin installed and specified in the config. Some frameworks might require extra configuration to work - check their Vite related documentation to be sure. ::: code-group diff --git a/packages/browser/src/node/plugin.ts b/packages/browser/src/node/plugin.ts index a0eca4c3d..b21daebb3 100644 --- a/packages/browser/src/node/plugin.ts +++ b/packages/browser/src/node/plugin.ts @@ -328,19 +328,17 @@ export default (browserServer: BrowserServer, base = '/'): Plugin[] => { viteConfig.esbuild.legalComments = 'inline' } - const server = resolveApiServerConfig( + const api = resolveApiServerConfig( viteConfig.test?.browser || {}, defaultBrowserPort, ) || { port: defaultBrowserPort, } - // browser never runs in middleware mode - server.middlewareMode = false - viteConfig.server = { ...viteConfig.server, - ...server, + ...api, + middlewareMode: false, open: false, } viteConfig.server.fs ??= {}