From 4cfc54931d765a012b7836e60ba556d9c7b421ff Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Tue, 11 Jul 2023 14:49:19 +0200 Subject: fix(node/http): allow callback in first argument of end call (#19778) Closes #19762 --- cli/tests/unit_node/http_test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'cli') diff --git a/cli/tests/unit_node/http_test.ts b/cli/tests/unit_node/http_test.ts index baebd4678..a84136052 100644 --- a/cli/tests/unit_node/http_test.ts +++ b/cli/tests/unit_node/http_test.ts @@ -707,3 +707,31 @@ Deno.test( await promise; }, ); + +Deno.test( + "[node/http] client end with callback", + { permissions: { net: true } }, + async () => { + const promise = deferred(); + let body = ""; + + const request = http.request( + "http://localhost:4545/http_version", + (resp) => { + resp.on("data", (chunk) => { + body += chunk; + }); + + resp.on("end", () => { + promise.resolve(); + }); + }, + ); + request.on("error", promise.reject); + request.end(); + + await promise; + + assertEquals(body, "HTTP/1.1"); + }, +); -- cgit v1.2.3