supertest
supertest copied to clipboard
Discourage implicit use of ephemeral ports in supertest.serverAddress
I've been search for flakes in my test for weeks and I think the solution is around supertest's usage of ephemeral ports (binding to port 0).
Full writeup at at https://stackoverflow.com/questions/63343123/nodesupertest-flakes-with-client-network-socket-disconnected-before-secure-tls/63343124#63343124.
tldr; supertest.serverAddress will call app.listen(0) if the server isn't running yet. But the socket will have the SO_REUSEADDR flag set which means it can conflict with any other process that's also using SO_REUSEADDR on a port in the ephemeral range. This causes the client to spuriously fail at making a connection.
I have debugged whole day to find macbook related ephemeral ports, i believe we should be given option to pick a port and more granular options. macbook has AV, firewall and other stuff running, returning 403 on some of them and supertest replies that express did this.