Skip to content

test: let the OS choose the vitest browser fixture's server port - #838

Merged
wan9chi merged 1 commit into
mainfrom
claude/dazzling-cartwright-4d060c
Oct 12, 2026
Merged

wan9chi merged 1 commit into
mainfrom
claude/dazzling-cartwright-4d060c

Conversation

@wan9chi

@wan9chi wan9chi commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Motivation

vitest_browser_cache::vitest_browser_caches_inputs_and_restores_outputs fails intermittently on Windows runners in the Test (windows-ignored) job:

Error: listen EACCES: permission denied ::1:63315

63315 is the fixed default port for Vitest browser mode's server. Windows reserves dynamic port ranges (Hyper-V/WinNAT excluded port ranges), and listening on a reserved port fails with EACCES. Vite only tries another port on EADDRINUSE, so the run fails, dist/result.json is never written, and the snapshot diverges. It depends on which runner the job lands on: it failed on #824 and #825 and passed on other runs of the same code.

Changes

The fixture's browser server now listens on port 0, so the OS chooses a free port. Vite supports server.listen(0) directly, but the config can't request it the normal way:

  • test.api: { port: 0 }: Vitest only copies api.port when it is truthy, so 0 falls back to 63315.
  • Setting test.api at all, even with a concrete port, adds an API started at http://localhost:<port>/ banner line that would change the snapshot. test.browser.api prints a deprecation warning in Vitest 5.

Instead, a small enforce: 'post' plugin sets test.api.port = 0 after Vitest resolves test.api. The banner stays unchanged, and the snapshot is identical.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

fspy benchmark

linux

dynamic/launch             change  +1.81%  [-13.90% .. +20.58%]  overhead   +58.39%
dynamic/access             change  -0.35%  [-15.53% .. +72.88%]  overhead   +11.12%
dynamic/access-relative    change  -0.39%  [ -6.64% ..  +5.03%]  overhead   +44.51%
dynamic/access-contended   change  +1.18%  [ -4.36% ..  +5.62%]  overhead    +4.88%
static/launch              change  +6.57%  [-21.10% .. +43.68%]  overhead  +168.19%
static/access              change  -0.67%  [-18.52% .. +18.87%]  overhead  +852.64%
static/access-relative     change  -2.92%  [-10.28% ..  +5.22%]  overhead +1228.54%
static/access-contended    change  +2.79%  [ -5.63% .. +10.34%]  overhead +2220.67%

macos

dynamic/launch             change  +0.14%  [ -4.03% ..  +4.79%]  overhead  +234.18%
dynamic/access             change  -0.33%  [-56.44% .. +13.08%]  overhead    +5.47%
dynamic/access-relative    change  -0.87%  [-15.90% .. +16.35%]  overhead  +248.98%
dynamic/access-contended   change  +2.38%  [-50.83% .. +637.48%]  overhead    +2.72%

windows

dynamic/launch             change  +0.51%  [ -2.85% ..  +3.89%]  overhead   +26.13%
dynamic/access             change  +0.00%  [ -1.23% ..  +0.93%]  overhead    +1.15%
dynamic/access-relative    change  +0.19%  [ -0.92% ..  +0.96%]  overhead    +0.95%
dynamic/access-contended   change  +0.00%  [ -1.06% ..  +1.31%]  overhead    +1.31%

Vitest browser mode listens on the fixed port 63315 by default. On Windows
runners that port can fall inside an excluded port range, where listening
fails with EACCES and Vitest does not fall back to another port.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wan9chi
wan9chi force-pushed the claude/dazzling-cartwright-4d060c branch from 410f406 to 0db9d70 Compare October 12, 2026 05:25
@wan9chi
wan9chi merged commit e5d73d2 into main Oct 12, 2026
21 checks passed
@wan9chi
wan9chi deleted the claude/dazzling-cartwright-4d060c branch October 12, 2026 05:31
fengmk2 added a commit to voidzero-dev/vite-plus that referenced this pull request Oct 12, 2026
The browser snapshots use Vitest's fixed API port, which Windows can
reserve. This causes intermittent `EACCES` failures.

Set `test.api.port` to `0` in a post-configuration hook, after Vitest
resolves its defaults. The OS selects an available port when the server
binds. This follows
[vite-task#838](voidzero-dev/vite-task#838) and
preserves the snapshot assertions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant