summaryrefslogtreecommitdiff
path: root/cli/js/fetch_test.ts
diff options
context:
space:
mode:
authorserverhiccups <hiccup@hiccup01.com>2020-02-04 03:54:47 +1300
committerGitHub <noreply@github.com>2020-02-03 15:54:47 +0100
commit2b0cf74a8f6335ae4e8ef2dfe1010d2695b1c518 (patch)
treed2d725273149dc17e10c306fa4aeaa1a02685530 /cli/js/fetch_test.ts
parentfba40d86c4cbb8ff406175820ea9a2d9eb2b40cd (diff)
Make fetch API more standards compliant (#3667)
Diffstat (limited to 'cli/js/fetch_test.ts')
-rw-r--r--cli/js/fetch_test.ts75
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");
+});