From 12f9f1f3eb2751fdbba1563a53a0a55581cc43e3 Mon Sep 17 00:00:00 2001 From: Lukas Wallrich Date: Wed, 21 Oct 2026 19:09:56 +0100 Subject: [PATCH 1/2] Allow the browser-test port to be set with TEST_PORT Lets several worktrees run the browser suite at the same time. Co-Authored-By: Claude Opus 5.5 --- CONTRIBUTING.md | 2 +- tests/browser.test.cjs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2d0ccaed..93876788 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,7 +33,7 @@ npm ci npm test ``` -The tests start their own Python HTTP server on port 8897 and use installed Chrome by default. To use bundled Chromium instead: +The tests start their own Python HTTP server on port 8897 (set `TEST_PORT` to change it) and use installed Chrome by default. To use bundled Chromium instead: ```sh npx playwright install chromium diff --git a/tests/browser.test.cjs b/tests/browser.test.cjs index 7898afbd..5e810591 100644 --- a/tests/browser.test.cjs +++ b/tests/browser.test.cjs @@ -4,9 +4,10 @@ const {chromium} = require('playwright'); const {spawn} = require('node:child_process'); const fs = require('node:fs'); let browser, server; -const base = 'http://127.0.0.1:8897/'; +const port = process.env.TEST_PORT || '8897'; +const base = `http://127.0.0.1:${port}/`; before(async()=>{ - server=spawn(process.env.PYTHON || 'python3',['-m','http.server','8897','--bind','127.0.0.1'],{stdio:'ignore'}); + server=spawn(process.env.PYTHON || 'python3',['-m','http.server',port,'--bind','127.0.0.1'],{stdio:'ignore'}); // Consume the readiness response so its open stream does not outlive the hook. for(let i=0;i<50;i++){try{await (await fetch(base)).arrayBuffer();break;}catch{await new Promise(r=>setTimeout(r,100));}} browser=await chromium.launch({channel:process.env.BROWSER_CHANNEL || 'chrome',headless:true}); From 927e7f1dac47ea643bc1bd635a6995afaf7238b4 Mon Sep 17 00:00:00 2001 From: Lukas Wallrich Date: Wed, 21 Oct 2026 19:16:15 +0100 Subject: [PATCH 2/2] Fail the browser suite when the test server cannot bind its port Co-Authored-By: Claude Opus 5.5 --- tests/browser.test.cjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/browser.test.cjs b/tests/browser.test.cjs index 5e810591..9d81f81d 100644 --- a/tests/browser.test.cjs +++ b/tests/browser.test.cjs @@ -8,8 +8,12 @@ const port = process.env.TEST_PORT || '8897'; const base = `http://127.0.0.1:${port}/`; before(async()=>{ server=spawn(process.env.PYTHON || 'python3',['-m','http.server',port,'--bind','127.0.0.1'],{stdio:'ignore'}); + // A server that exits early usually means the port is taken; fail rather than test another server's files. + let exited=false;server.on('exit',()=>{exited=true;}); // Consume the readiness response so its open stream does not outlive the hook. for(let i=0;i<50;i++){try{await (await fetch(base)).arrayBuffer();break;}catch{await new Promise(r=>setTimeout(r,100));}} + await new Promise(r=>setTimeout(r,200)); + if(exited) throw new Error(`Test server could not start on port ${port}; set TEST_PORT to a free port.`); browser=await chromium.launch({channel:process.env.BROWSER_CHANNEL || 'chrome',headless:true}); }); after(async()=>{await browser?.close();server?.kill();});