From 502ecbfea865fff3a85a172298bf5db6a6b2ba34 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 11 Oct 2024 17:46:07 +0200 Subject: [PATCH] docs: mention that the browser mode uses 63315 port (#6691) --- docs/config/index.md | 2 +- docs/guide/browser/index.md | 4 ++++ packages/browser/src/node/plugin.ts | 8 +++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index e9df0fc6090c..0080c8937c69 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 5eacddc8b69e..14dc37749b7f 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 a0eca4c3d1a0..b21daebb3399 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 ??= {}