From 5aca8b9e5d6420c65ab3ecf516e9d8c8eaaee28f Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Tue, 6 Jun 2023 16:37:10 +0200 Subject: fix(node/http): use fake socket and proper url handling (#19340) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/denoland/deno/issues/19349 --------- Co-authored-by: Bartek IwaƄczuk --- cli/tests/unit_node/http_test.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'cli/tests') diff --git a/cli/tests/unit_node/http_test.ts b/cli/tests/unit_node/http_test.ts index 05731f543..6b0228274 100644 --- a/cli/tests/unit_node/http_test.ts +++ b/cli/tests/unit_node/http_test.ts @@ -195,11 +195,14 @@ Deno.test("[node/http] request default protocol", async () => { // @ts-ignore IncomingMessageForClient // deno-lint-ignore no-explicit-any let clientRes: any; + // deno-lint-ignore no-explicit-any + let clientReq: any; server.listen(() => { - const req = http.request( + clientReq = http.request( // deno-lint-ignore no-explicit-any { host: "localhost", port: (server.address() as any).port }, (res) => { + assert(res.socket instanceof EventEmitter); assertEquals(res.complete, false); res.on("data", () => {}); res.on("end", () => { @@ -210,13 +213,14 @@ Deno.test("[node/http] request default protocol", async () => { promise2.resolve(); }, ); - req.end(); + clientReq.end(); }); server.on("close", () => { promise.resolve(); }); await promise; await promise2; + assert(clientReq.socket instanceof EventEmitter); assertEquals(clientRes!.complete, true); }); @@ -596,3 +600,24 @@ Deno.test("[node/http] ClientRequest PUT", async () => { await def; assertEquals(body, "hello world"); }); + +Deno.test("[node/http] ClientRequest search params", async () => { + let body = ""; + const def = deferred(); + const req = http.request({ + host: "localhost:4545", + path: "search_params?foo=bar", + }, (resp) => { + resp.on("data", (chunk) => { + body += chunk; + }); + + resp.on("end", () => { + def.resolve(); + }); + }); + req.once("error", (e) => def.reject(e)); + req.end(); + await def; + assertEquals(body, "foo=bar"); +}); -- cgit v1.2.3