Skip to content

Commit 7ed5570

Browse files
authored
fix(test): avoid fixture server localhost DNS race (#2999)
1 parent b7a42ec commit 7ed5570

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

tests/helpers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export async function startFixtureServer(
9696
holdUntilCrawlEnd: true,
9797
},
9898
server: {
99+
// Avoid localhost resolving to ::1 when the test server is bound to IPv4.
100+
host: "127.0.0.1",
99101
port: 0,
100102
cors: false,
101103
...opts?.server,
@@ -108,7 +110,8 @@ export async function startFixtureServer(
108110
await server.listen();
109111
const addr = server.httpServer?.address();
110112
if (addr && typeof addr === "object") {
111-
baseUrl = `http://localhost:${addr.port}`;
113+
const host = addr.family === "IPv6" ? `[${addr.address}]` : addr.address;
114+
baseUrl = `http://${host}:${addr.port}`;
112115
}
113116
}
114117

0 commit comments

Comments
 (0)