Skip to content

Commit 9398aff

Browse files
committed
test: fetch the bound address
With both 127.0.0.1 and ::1 for localhost, an old fetch() may try only the address that the server did not bind, as Bun 1.4.0 does.
1 parent 57f830b commit 9398aff

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎packages/bongo/src/utils/http.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@ describe('start', () => {
290290
try {
291291
expect(opts.port).toBe(port + 1);
292292
expect(server.listenerCount('listening')).toBe(createServer().listenerCount('listening'));
293-
let res = await fetch(`http://localhost:${opts.port}/`);
293+
// the address that localhost resolved to, since an old fetch() may try only the other one
294+
let info = server.address();
295+
if (!info || typeof info === 'string') throw new Error('no address');
296+
let res = await fetch(`http://${info.family === 'IPv6' ? `[${info.address}]` : info.address}:${opts.port}/`);
294297
expect(await res.text()).toBe('<h1>ok</h1>');
295298
} finally {
296299
server.close();

0 commit comments

Comments
 (0)