[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

test: make server-url assertions immune to ephemeral-port collisions

Vladimir Sheremet (Jul 27, 2026, 5:29 PM +0200) 01d36892 d80e9591

+17 -7
+2 -2
test/browser/specs/server-url.test.ts
··· 13 13 const url = ctx?.projects[0].vite.resolvedUrls?.local[0] 14 14 expect(stderr).toBe('') 15 15 expect.assert(url) 16 - expect(new URL(url).port).toBe('51133') 16 + expect(new URL(url).port).toBe('31133') 17 17 }) 18 18 19 19 test('server-url https', async () => { ··· 25 25 expect(stderr).toBe('') 26 26 const url = ctx?.projects[0].vite.resolvedUrls?.local[0] 27 27 expect.assert(url) 28 - expect(new URL(url).port).toBe('51122') 28 + expect(new URL(url).port).toBe('31122') 29 29 expect(stdout).toReportSummaryTestFiles({ passed: instances.length }) 30 30 })
+11 -4
test/e2e/test/server-url.test.ts
··· 3 3 4 4 import { runInlineTests } from '../../test-utils' 5 5 6 + // `api: true` must resolve to the default port, but which port Vite actually 7 + // binds is not asserted: 51204 sits inside the OS ephemeral port range, and 8 + // when an unrelated outbound socket happens to hold it, Vite silently binds 9 + // port+1 (`strictPort` is off and the "Port is in use" notice is info-level, 10 + // below the logger's `warn` level) 6 11 it('api server-url http', async () => { 7 - const { stdout, stderr } = await runInlineTests( 12 + const { stdout, stderr, ctx } = await runInlineTests( 8 13 { 'basic.test.js': `test("basic")` }, 9 14 { 10 15 api: true, ··· 12 17 }, 13 18 ) 14 19 expect(stderr).toBe('') 15 - expect(stdout).toContain('API started at http://localhost:51204/') 20 + expect(ctx!.config.api.port).toBe(51204) 21 + expect(stdout).toMatch(/API started at http:\/\/localhost:\d+\//) 16 22 expect(stdout).toContain('Test Files 1 skipped') 17 23 }) 18 24 19 25 it('api server-url https', async () => { 20 - const { stdout, stderr } = await runInlineTests( 26 + const { stdout, stderr, ctx } = await runInlineTests( 21 27 { 'basic.test.js': `test("basic")` }, 22 28 { 23 29 api: true, ··· 28 34 }, 29 35 ) 30 36 expect(stderr).toBe('') 31 - expect(stdout).toContain('API started at https://localhost:51204/') 37 + expect(ctx!.config.api.port).toBe(51204) 38 + expect(stdout).toMatch(/API started at https:\/\/localhost:\d+\//) 32 39 expect(stdout).toContain('Test Files 1 skipped') 33 40 }) 34 41
+4 -1
test/browser/fixtures/server-url/vitest.config.ts
··· 23 23 !!process.env.TEST_HTTPS && basicSsl(), 24 24 ], 25 25 test: { 26 - api: process.env.TEST_HTTPS ? 51122 : 51133, 26 + // below the OS ephemeral port range (32768+ on Linux): a kernel-assigned 27 + // outbound socket holding the fixed port would make Vite silently bind 28 + // port+1 and fail the exact-port assertions 29 + api: process.env.TEST_HTTPS ? 31122 : 31133, 27 30 browser: { 28 31 enabled: true, 29 32 provider: configuredProvider,