Skip to content

Commit 89b42bf

Browse files
test(web): browser tests from different checkouts no longer fight over one port (#20875)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent b827ca4 commit 89b42bf

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎apps/web/vite.config.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { playwright } from "vite-plus/test/browser-playwright";
77
import { defineProject, type TestProjectInlineConfiguration } from "vite-plus/test/config";
88
import "vite-plus/test/config";
99
import { defineConfig, type Connect, type Plugin } from "vite-plus";
10+
import * as Hash from "effect/Hash";
1011
import pkg from "./package.json" with { type: "json" };
1112

1213
import {
@@ -80,6 +81,12 @@ const unitTestProject = {
8081

8182
// Anything that renders React or touches the DOM is named *.browser.test.{ts,tsx} and runs
8283
// in headless Chromium through the same plugins as the app, so it exercises compiled code.
84+
// Vitest's fixed browser API port (63315) collides when two checkouts run
85+
// browser tests at once, and `server.strictPort` above is inherited, so the
86+
// second run fails instead of moving on. Hash the checkout path like
87+
// scripts/dev-runner.ts does, into 61000-64999 (above Linux's ephemeral range).
88+
const browserTestApiPort = 61_000 + ((Hash.string(import.meta.dirname) >>> 0) % 4_000);
89+
8390
const browserTestProject = {
8491
extends: true,
8592
// Pre-bundled so the first test importing userEvent does not trigger a mid-run reload.
@@ -89,6 +96,7 @@ const browserTestProject = {
8996
include: ["src/**/*.browser.test.{ts,tsx}"],
9097
hookTimeout: 15_000,
9198
testTimeout: 15_000,
99+
api: { port: browserTestApiPort, strictPort: false },
92100
browser: {
93101
enabled: true,
94102
headless: true,

0 commit comments

Comments
 (0)