diff --git a/src/__tests__/_helper.ts b/src/__tests__/_helper.ts index 5ac1e3d..d069af4 100644 --- a/src/__tests__/_helper.ts +++ b/src/__tests__/_helper.ts @@ -35,6 +35,7 @@ export const mockServer = (): Server => { socket.write('+HI {"v":2,"s":"abc","i":3}\r\n'); server.emit("HI"); }); + server.on('error', console.error); return server; }; @@ -45,12 +46,15 @@ type ServerUser = { export const mocked = async (fn: ServerUser): Promise => { const server = mockServer(); const port = await getPort(); - server.listen(port, "127.0.0.1"); - try { - return fn(server, port); - } finally { - await new Promise((resolve) => server.close(() => resolve())); - } + return new Promise((resolve, reject) => { + server.listen({ port, host: "127.0.0.1" }, async () => { + try { + resolve(await fn(server, port)); + } finally { + server.close(resolve); + } + }); + }) }; mocked.ok = () => ({ socket }: ServerControl) => {