Skip to content

Commit df5a591

Browse files
authored
fix: make hmr tests pass in CI (#2962)
Assorted fixes to make them pass in CI: - opus decided to copy the existing pattern of passing inputs to the tests.reusable.yaml workflow file from ci.yaml, which serves no purpose - NO_COLOR to prevent ascii color codes from messing up regex extraction of the 'vite dev' port - make 'vite dev' startup in the HMR test more reliable (manually randomize port, and allow vite to try multiple ports on retry)
1 parent 3b2cf74 commit df5a591

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

.github/workflows/webview-tests.reusable.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Webview Tests (Reusable)
22

33
on:
4-
workflow_call: {}
4+
workflow_call:
55

66
permissions:
77
contents: read
@@ -92,8 +92,6 @@ jobs:
9292
hmr-tests:
9393
name: "HMR Tests (Hot Reload)"
9494
runs-on: ubuntu-latest
95-
# Only run on main/canary
96-
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/canary'
9795
timeout-minutes: 20
9896
steps:
9997
- uses: actions/checkout@v4

typescript2/app-vscode-webview/src/hot-reload.hmr.test.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,19 @@ function waitForOutput(
6464

6565
/**
6666
* Start the Vite dev server and wait for it to be ready.
67-
* Uses a random available port.
67+
* Uses a random port between 4900 and 4999.
6868
*/
6969
async function startDevServer(): Promise<DevServer> {
7070
// Use --force to re-optimize deps and avoid 504 "Outdated Optimize Dep" errors
71-
// Use --port 0 to let Vite pick a random available port
72-
console.log(`[vite] Starting dev server in ${projectRoot}`)
73-
const proc = spawn('pnpm', ['dev', '--force', '--port', '0'], {
71+
// Use a random port between 4900 and 4999 to avoid conflicts
72+
// Disable strictPort so Vite will try next available port if chosen port is in use
73+
const randomPort = Math.floor(Math.random() * 100) + 4900
74+
console.log(`[vite] Starting dev server in ${projectRoot} on port ${randomPort}`)
75+
const proc = spawn('pnpm', ['dev', '--force', '--port', String(randomPort), '--strictPort', 'false'], {
7476
cwd: projectRoot,
7577
stdio: ['pipe', 'pipe', 'pipe'],
7678
shell: true,
79+
env: { ...process.env, NO_COLOR: '1' },
7780
})
7881

7982
// Collect output and parse port
@@ -93,12 +96,15 @@ async function startDevServer(): Promise<DevServer> {
9396
}
9497

9598
// Parse port from Vite output: "Local: http://localhost:XXXX/"
96-
const match = text.match(/Local:\s*http:\/\/localhost:(\d+)/)
97-
if (match) {
98-
port = parseInt(match[1], 10)
99-
console.log(`[vite] Dev server running on port ${port}`)
100-
clearTimeout(timeout)
101-
resolve(port)
99+
// Match against accumulated output in case the line arrives in multiple chunks
100+
if (!port) {
101+
const match = output.match(/Local:\s*http:\/\/localhost:(\d+)/)
102+
if (match) {
103+
port = parseInt(match[1], 10)
104+
console.log(`[vite] Dev server running on port ${port}`)
105+
clearTimeout(timeout)
106+
resolve(port)
107+
}
102108
}
103109
}
104110

0 commit comments

Comments
 (0)