summaryrefslogtreecommitdiff
path: root/cli/tests/unit/fetch_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit/fetch_test.ts')
-rw-r--r--cli/tests/unit/fetch_test.ts73
1 files changed, 28 insertions, 45 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index 427ab9b53..a46104ff8 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -79,7 +79,7 @@ unitTest(
async (): Promise<void> => {
await fetch("http://<invalid>/");
},
- URIError,
+ TypeError,
);
},
);
@@ -129,18 +129,6 @@ unitTest({ perms: { net: true } }, async function fetchBlob(): Promise<void> {
assertEquals(blob.size, Number(headers.get("Content-Length")));
});
-unitTest({ perms: { net: true } }, async function fetchBodyUsed(): Promise<
- void
-> {
- const response = await fetch("http://localhost:4545/cli/tests/fixture.json");
- assertEquals(response.bodyUsed, false);
- // deno-lint-ignore no-explicit-any
- (response as any).bodyUsed = true;
- assertEquals(response.bodyUsed, false);
- await response.blob();
- assertEquals(response.bodyUsed, true);
-});
-
unitTest(
{ perms: { net: true } },
async function fetchBodyUsedReader(): Promise<void> {
@@ -278,7 +266,6 @@ unitTest(
TypeError,
"Invalid form data",
);
- await response.body.cancel();
},
);
@@ -424,10 +411,11 @@ unitTest(
perms: { net: true },
},
async function fetchWithInfRedirection(): Promise<void> {
- const response = await fetch("http://localhost:4549/cli/tests"); // will redirect to the same place
- assertEquals(response.status, 0); // network error
- assertEquals(response.type, "error");
- assertEquals(response.ok, false);
+ await assertThrowsAsync(
+ () => fetch("http://localhost:4549/cli/tests"),
+ TypeError,
+ "redirect",
+ );
},
);
@@ -661,8 +649,8 @@ unitTest(
const actual = new TextDecoder().decode(buf.bytes());
const expected = [
"POST /blah HTTP/1.1\r\n",
- "foo: Bar\r\n",
"hello: World\r\n",
+ "foo: Bar\r\n",
"accept: */*\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
"accept-encoding: gzip, br\r\n",
@@ -695,9 +683,9 @@ unitTest(
const actual = new TextDecoder().decode(buf.bytes());
const expected = [
"POST /blah HTTP/1.1\r\n",
- "content-type: text/plain;charset=UTF-8\r\n",
- "foo: Bar\r\n",
"hello: World\r\n",
+ "foo: Bar\r\n",
+ "content-type: text/plain;charset=UTF-8\r\n",
"accept: */*\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
"accept-encoding: gzip, br\r\n",
@@ -733,8 +721,8 @@ unitTest(
const actual = new TextDecoder().decode(buf.bytes());
const expected = [
"POST /blah HTTP/1.1\r\n",
- "foo: Bar\r\n",
"hello: World\r\n",
+ "foo: Bar\r\n",
"accept: */*\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
"accept-encoding: gzip, br\r\n",
@@ -770,8 +758,9 @@ unitTest(
}); // will redirect to http://localhost:4545/
assertEquals(response.status, 301);
assertEquals(response.url, "http://localhost:4546/");
- assertEquals(response.type, "default");
+ assertEquals(response.type, "basic");
assertEquals(response.headers.get("Location"), "http://localhost:4545/");
+ await response.body!.cancel();
},
);
@@ -780,21 +769,14 @@ unitTest(
perms: { 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(
- "Response.text() didn't throw on a filtered response without a body (type error)",
- );
- } catch (_e) {
- return;
- }
+ await assertThrowsAsync(
+ () =>
+ fetch("http://localhost:4546/", {
+ redirect: "error",
+ }),
+ TypeError,
+ "redirect",
+ );
},
);
@@ -803,7 +785,10 @@ unitTest(function responseRedirect(): void {
assertEquals(redir.status, 301);
assertEquals(redir.statusText, "");
assertEquals(redir.url, "");
- assertEquals(redir.headers.get("Location"), "example.com/newLocation");
+ assertEquals(
+ redir.headers.get("Location"),
+ "http://js-unit-tests/foo/example.com/newLocation",
+ );
assertEquals(redir.type, "default");
});
@@ -1004,10 +989,7 @@ unitTest(function fetchResponseConstructorInvalidStatus(): void {
fail(`Invalid status: ${status}`);
} catch (e) {
assert(e instanceof RangeError);
- assertEquals(
- e.message,
- `The status provided (${status}) is outside the range [200, 599]`,
- );
+ assert(e.message.endsWith("is outside the range [200, 599]."));
}
}
});
@@ -1024,8 +1006,9 @@ unitTest(function fetchResponseEmptyConstructor(): void {
assertEquals([...response.headers], []);
});
+// TODO(lucacasonato): reenable this test
unitTest(
- { perms: { net: true } },
+ { perms: { net: true }, ignore: true },
async function fetchCustomHttpClientParamCertificateSuccess(): Promise<
void
> {
@@ -1115,8 +1098,8 @@ unitTest(
const actual = new TextDecoder().decode(buf.bytes());
const expected = [
"POST /blah HTTP/1.1\r\n",
- "foo: Bar\r\n",
"hello: World\r\n",
+ "foo: Bar\r\n",
"accept: */*\r\n",
`user-agent: Deno/${Deno.version.deno}\r\n`,
"accept-encoding: gzip, br\r\n",