diff options
author | Marvin Hagemeister <marvin@deno.com> | 2024-07-04 18:28:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-04 18:28:48 +0200 |
commit | 96b527b8df3c9e7e29c98a6a0d6876089b88bc09 (patch) | |
tree | 52337d1d3b597df97232c8c10262b1ef7fa56c8f /tests/unit_node/http_test.ts | |
parent | f632b4a92e4e2c552cf31749792075bad0814c22 (diff) |
fix(node/http): don't throw on .address() before .listen() (#24432)
It's perfectly valid to access `server.address()` before calling
`.listen()`. Until a server actively listens on a socket Node will
return `null` here, but we threw a "Cannot access property 'port' of
undefined" instead.
This was discovered when inspecting failures in Koa's test suite with
Deno.
Diffstat (limited to 'tests/unit_node/http_test.ts')
-rw-r--r-- | tests/unit_node/http_test.ts | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts index aeb92f129..0935aeac0 100644 --- a/tests/unit_node/http_test.ts +++ b/tests/unit_node/http_test.ts @@ -1251,3 +1251,8 @@ Deno.test("[node/http] http.request() post streaming body works", async () => { clearTimeout(timeout); assertEquals(server.listening, false); }); + +Deno.test("[node/http] Server.address() can be null", () => { + const server = http.createServer((_req, res) => res.end("it works")); + assertEquals(server.address(), null); +}); |