From 5e6261affdbf4b0c18778e6ae5cc7b233953debe Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 22 Apr 2026 19:40:13 +0200 Subject: [PATCH] chore(tests): add support for missing localhost in DNS --- tests/_registryServer.mjs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/_registryServer.mjs b/tests/_registryServer.mjs index f9e8b9db3..51f8bcb1a 100644 --- a/tests/_registryServer.mjs +++ b/tests/_registryServer.mjs @@ -187,7 +187,15 @@ if (process.env.AUTH_TYPE === `PROXY`) { }); }); proxy.listen(0, `localhost`); - await once(proxy, `listening`); + await once(proxy, `listening`).catch(e => { + if (e?.code === `ENOTFOUND`) { + // localhost is not found + proxy.close(); + proxy.listen(); // Fallback to unspecified address + return once(proxy, `listening`); + } + throw e; + }); const {address, port} = proxy.address(); process.env.ALL_PROXY = `http://${address.includes(`:`) ? `[${address}]` : address}:${port}`; @@ -195,7 +203,15 @@ if (process.env.AUTH_TYPE === `PROXY`) { } server.listen(0, `localhost`); -await once(server, `listening`); +await once(server, `listening`).catch(e => { + if (e?.code === `ENOTFOUND`) { + // localhost is not found + server.close(); + server.listen(); // Fallback to unspecified address + return once(server, `listening`); + } + throw e; +}); const {address, port} = server.address(); switch (process.env.AUTH_TYPE) {