From 6e0bf093c558358c463109637615fddc4020eeac Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Wed, 31 May 2023 20:06:21 +0200 Subject: refactor: further work on node http client (#19327) Closes https://github.com/denoland/deno/issues/18300 --- cli/tests/unit_node/http_test.ts | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'cli/tests/unit_node') diff --git a/cli/tests/unit_node/http_test.ts b/cli/tests/unit_node/http_test.ts index d1ed11632..05731f543 100644 --- a/cli/tests/unit_node/http_test.ts +++ b/cli/tests/unit_node/http_test.ts @@ -531,3 +531,68 @@ Deno.test("[node/http] ClientRequest uses HTTP/1.1", async () => { await def; assertEquals(body, "HTTP/1.1"); }); + +Deno.test("[node/http] ClientRequest setTimeout", async () => { + let body = ""; + const def = deferred(); + const timer = setTimeout(() => def.reject("timed out"), 50000); + const req = http.request("http://localhost:4545/http_version", (resp) => { + resp.on("data", (chunk) => { + body += chunk; + }); + + resp.on("end", () => { + def.resolve(); + }); + }); + req.setTimeout(120000); + req.once("error", (e) => def.reject(e)); + req.end(); + await def; + clearTimeout(timer); + assertEquals(body, "HTTP/1.1"); +}); + +Deno.test("[node/http] ClientRequest PATCH", async () => { + let body = ""; + const def = deferred(); + const req = http.request("http://localhost:4545/echo_server", { + method: "PATCH", + }, (resp) => { + resp.on("data", (chunk) => { + body += chunk; + }); + + resp.on("end", () => { + def.resolve(); + }); + }); + req.write("hello "); + req.write("world"); + req.once("error", (e) => def.reject(e)); + req.end(); + await def; + assertEquals(body, "hello world"); +}); + +Deno.test("[node/http] ClientRequest PUT", async () => { + let body = ""; + const def = deferred(); + const req = http.request("http://localhost:4545/echo_server", { + method: "PUT", + }, (resp) => { + resp.on("data", (chunk) => { + body += chunk; + }); + + resp.on("end", () => { + def.resolve(); + }); + }); + req.write("hello "); + req.write("world"); + req.once("error", (e) => def.reject(e)); + req.end(); + await def; + assertEquals(body, "hello world"); +}); -- cgit v1.2.3