Skip to content

Commit 3e6cd06

Browse files
author
Gabi
committed
fix: serve tests wait for TCP socket before fetching
The serve start/stop tests polled for the ready-file (confirming the port was bound) but then immediately called fetch() without waiting for the server to accept connections. On slow CI runners (Node 18/20), the socket wasn't ready yet, causing flaky ECONNREFUSED failures. Both tests now use the existing waitForHttpServer() helper to confirm the server accepts connections before making requests.
1 parent f348e16 commit 3e6cd06

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

tests/tools.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,14 +750,16 @@ describe('serve start/stop', () => {
750750
const dir = mkdtempSync(join(tmpdir(), 'pixelslop-serve-'));
751751
writeFileSync(join(dir, 'index.html'), '<html><body>test</body></html>');
752752

753-
// Start — need a brief wait for the detached process to bind
753+
// Start — the ready-file poll confirms the port is bound, but on slow
754+
// CI runners the TCP socket may not accept connections immediately.
754755
const startResult = runJson(`serve start --root "${dir}"`, dir);
755756
assert.ok(startResult.url, 'should return a URL');
756757
assert.ok(startResult.port > 0, 'should return a valid port');
757758
assert.ok(startResult.pid > 0, 'should return a PID');
758759
assert.ok(startResult.pid_file.includes(join(dir, '.pixelslop')), 'should store state under the project');
759760

760-
// Verify the server actually serves content
761+
// Wait for the server to actually accept connections before fetching
762+
await waitForHttpServer(startResult.port);
761763
const response = await fetch(startResult.url);
762764
assert.equal(response.status, 200, 'should serve 200');
763765
const body = await response.text();
@@ -785,7 +787,9 @@ describe('serve start/stop', () => {
785787
writeFileSync(join(dirB, 'index.html'), '<html><body>beta</body></html>');
786788

787789
const startA = runJson(`serve start --root "${dirA}"`, dirA);
790+
await waitForHttpServer(startA.port);
788791
const startB = runJson(`serve start --root "${dirB}"`, dirB);
792+
await waitForHttpServer(startB.port);
789793

790794
const beforeStop = await (await fetch(startB.url)).text();
791795
assert.ok(beforeStop.includes('beta'));

0 commit comments

Comments
 (0)