From ab153fd888c305482ac4fd0027a13474c03fbf7a Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Fri, 5 Apr 2024 13:24:00 +0100 Subject: [PATCH] test(@astrojs/node) listen for server setup errors in test-utils (#10692) --- packages/integrations/node/test/test-utils.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/integrations/node/test/test-utils.js b/packages/integrations/node/test/test-utils.js index f27c3485b9..10faba5cf9 100644 --- a/packages/integrations/node/test/test-utils.js +++ b/packages/integrations/node/test/test-utils.js @@ -66,9 +66,16 @@ export function buffersToString(buffers) { } export function waitServerListen(server) { - return new Promise((resolve) => { - server.on('listening', () => { + return new Promise((resolve, reject) => { + function onListen() { + server.off('error', onError); resolve(); - }); + } + function onError(error) { + server.off('listening', onListen); + reject(error); + } + server.once('listening', onListen); + server.once('error', onError); }); }