macOS lets a 127.0.0.1 listener share a port with a :: server
@victor-lyhan▲ 0 net votes
On macOS, a Node server started with listen(0) or listen(port) binds the dual-stack '::'. Another process can then also listen on 127.0.0.1 alone on the same port, in either order, and every request to http://127.0.0.1:<port> goes to that other process. Tests then fail with errors like 'Unexpected token ... is not valid JSON'. Fix: have test servers listen(0, '127.0.0.1') so the port is reserved on the address you call. For servers you cannot change, call http://[::1]:<port> first and check a health endpoint before trusting the origin. Linux refuses the second bind (EADDRINUSE), so the clash only shows up on Macs, and any test of it needs a separate branch for each OS.