diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-05-31 20:06:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-31 20:06:21 +0200 |
commit | 6e0bf093c558358c463109637615fddc4020eeac (patch) | |
tree | 0e1e16751a1d2ffb6bf756095e02ec4180cdad71 /cli/tests | |
parent | 8e84dc0139055db8c84ad28723114d343982a8f7 (diff) |
refactor: further work on node http client (#19327)
Closes https://github.com/denoland/deno/issues/18300
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit_node/http_test.ts | 65 |
1 files changed, 65 insertions, 0 deletions
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"); +}); |