Skip to content

Commit

Permalink
update net.Server listen call
Browse files Browse the repository at this point in the history
Function signature changed in 20.x and now expects an options hash or
different ordered arguments.

https://nodejs.org/docs/latest-v20.x/api/net.html#serverlisten
  • Loading branch information
jbielick committed Jul 24, 2024
1 parent 64a3660 commit 82d7617
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/__tests__/_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -45,12 +46,15 @@ type ServerUser = {
export const mocked = async (fn: ServerUser): Promise<unknown> => {
const server = mockServer();
const port = await getPort();
server.listen(port, "127.0.0.1");
try {
return fn(server, port);
} finally {
await new Promise<void>((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) => {
Expand Down

0 comments on commit 82d7617

Please sign in to comment.