0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-20 22:12:38 -05:00

test(@astrojs/node) listen for server setup errors in test-utils (#10692)

This commit is contained in:
Raz Luvaton 2024-04-05 13:24:00 +01:00 committed by GitHub
parent e300ac9b9d
commit ab153fd888
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
});
}