From 02bc58d83253fd3be61787bb28b6b02e3aa71092 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 10 Apr 2020 09:51:17 -0400 Subject: BREAKING: Make fetch API more web compatible (#4687) - Removes the __fetch namespace from `deno types` - Response.redirect should be a static. - Response.body should not be AsyncIterable. - Disables the deno_proxy benchmark - Makes std/examples/curl.ts buffer the body before printing to stdout --- cli/js/tests/fetch_test.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'cli/js/tests/fetch_test.ts') diff --git a/cli/js/tests/fetch_test.ts b/cli/js/tests/fetch_test.ts index 432ecd59c..37fca2112 100644 --- a/cli/js/tests/fetch_test.ts +++ b/cli/js/tests/fetch_test.ts @@ -57,7 +57,7 @@ unitTest(async function fetchPerm(): Promise { unitTest({ perms: { net: true } }, async function fetchUrl(): Promise { const response = await fetch("http://localhost:4545/cli/tests/fixture.json"); assertEquals(response.url, "http://localhost:4545/cli/tests/fixture.json"); - response.body.close(); + const _json = await response.json(); }); unitTest({ perms: { net: true } }, async function fetchURL(): Promise { @@ -65,7 +65,7 @@ unitTest({ perms: { net: true } }, async function fetchURL(): Promise { new URL("http://localhost:4545/cli/tests/fixture.json") ); assertEquals(response.url, "http://localhost:4545/cli/tests/fixture.json"); - response.body.close(); + const _json = await response.json(); }); unitTest({ perms: { net: true } }, async function fetchHeaders(): Promise< @@ -75,7 +75,7 @@ unitTest({ perms: { net: true } }, async function fetchHeaders(): Promise< const headers = response.headers; assertEquals(headers.get("Content-Type"), "application/json"); assert(headers.get("Server")!.startsWith("SimpleHTTP")); - response.body.close(); + const _json = await response.json(); }); unitTest({ perms: { net: true } }, async function fetchBlob(): Promise { @@ -93,12 +93,16 @@ unitTest({ perms: { net: true } }, async function fetchBodyUsed(): Promise< assertEquals(response.bodyUsed, false); assertThrows((): void => { // Assigning to read-only property throws in the strict mode. + // @ts-ignore response.bodyUsed = true; }); await response.blob(); assertEquals(response.bodyUsed, true); }); +// TODO(ry) response.body shouldn't be iterable. Instead we should use +// response.body.getReader(). +/* unitTest({ perms: { net: true } }, async function fetchAsyncIterator(): Promise< void > { @@ -110,8 +114,9 @@ unitTest({ perms: { net: true } }, async function fetchAsyncIterator(): Promise< } assertEquals(total, Number(headers.get("Content-Length"))); - response.body.close(); + const _json = await response.json(); }); +*/ unitTest({ perms: { net: true } }, async function responseClone(): Promise< void @@ -506,16 +511,7 @@ unitTest( ); unitTest(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); + const redir = Response.redirect("example.com/newLocation", 301); assertEquals(redir.status, 301); assertEquals(redir.statusText, ""); assertEquals(redir.url, ""); -- cgit v1.2.3