diff options
Diffstat (limited to 'cli/js/fetch_test.ts')
-rw-r--r-- | cli/js/fetch_test.ts | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/cli/js/fetch_test.ts b/cli/js/fetch_test.ts index b8a7c8641..2b3d03a38 100644 --- a/cli/js/fetch_test.ts +++ b/cli/js/fetch_test.ts @@ -5,7 +5,8 @@ import { assert, assertEquals, assertStrContains, - assertThrows + assertThrows, + fail } from "./test_util.ts"; testPerm({ net: true }, async function fetchConnectionError(): Promise<void> { @@ -360,3 +361,75 @@ testPerm({ net: true }, async function fetchPostBodyTypedArray():Promise<void> { assertEquals(actual, expected); }); */ + +testPerm({ net: true }, async function fetchWithManualRedirection(): Promise< + void +> { + const response = await fetch("http://localhost:4546/", { + redirect: "manual" + }); // will redirect to http://localhost:4545/ + assertEquals(response.status, 0); + assertEquals(response.statusText, ""); + assertEquals(response.url, ""); + assertEquals(response.type, "opaqueredirect"); + try { + await response.text(); + fail( + "Reponse.text() didn't throw on a filtered response without a body (type opaqueredirect)" + ); + } catch (e) { + return; + } +}); + +testPerm({ net: true }, async function fetchWithErrorRedirection(): Promise< + void +> { + const response = await fetch("http://localhost:4546/", { + redirect: "error" + }); // will redirect to http://localhost:4545/ + assertEquals(response.status, 0); + assertEquals(response.statusText, ""); + assertEquals(response.url, ""); + assertEquals(response.type, "error"); + try { + await response.text(); + fail( + "Reponse.text() didn't throw on a filtered response without a body (type error)" + ); + } catch (e) { + return; + } +}); + +test(function responseRedirect(): void { + const response = new Response( + "example.com/beforeredirect", + 200, + "OK", + [["This-Should", "Disappear"]], + -1, + false, + null + ); + const redir = response.redirect("example.com/newLocation", 301); + assertEquals(redir.status, 301); + assertEquals(redir.statusText, ""); + assertEquals(redir.url, ""); + assertEquals(redir.headers.get("Location"), "example.com/newLocation"); + assertEquals(redir.type, "default"); +}); + +test(function responseConstructionHeaderRemoval(): void { + const res = new Response( + "example.com", + 200, + "OK", + [["Set-Cookie", "mysessionid"]], + -1, + false, + "basic", + null + ); + assert(res.headers.get("Set-Cookie") != "mysessionid"); +}); |