diff options
author | Long(Tony) Lian <1040424979@qq.com> | 2019-06-24 06:34:09 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-06-24 06:34:09 -0700 |
commit | 1d0d54247c0a5a69207f8e0b948d3b60287467eb (patch) | |
tree | e9d835c3a65ab88343cb751a09cda8e33f082040 /js/fetch_test.ts | |
parent | d82089ca358b7fa4d5e2b7a357f651364643de7a (diff) |
feat: fetch() now handles redirects (#2561)
Diffstat (limited to 'js/fetch_test.ts')
-rw-r--r-- | js/fetch_test.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/js/fetch_test.ts b/js/fetch_test.ts index 032727dbc..2020716bf 100644 --- a/js/fetch_test.ts +++ b/js/fetch_test.ts @@ -99,6 +99,32 @@ testPerm( } ); +testPerm({ net: true }, async function fetchWithRedirection(): Promise<void> { + const response = await fetch("http://localhost:4546/"); // will redirect to http://localhost:4545/ + assertEquals(response.status, 200); + const body = await response.text(); + assert(body.includes("<title>Directory listing for /</title>")); +}); + +testPerm({ net: true }, async function fetchWithRelativeRedirection(): Promise< + void +> { + const response = await fetch("http://localhost:4545/tests"); // will redirect to /tests/ + assertEquals(response.status, 200); + const body = await response.text(); + assert(body.includes("<title>Directory listing for /tests/</title>")); +}); + +// The feature below is not implemented, but the test should work after implementation +/* +testPerm({ net: true }, async function fetchWithInfRedirection(): Promise< + void +> { + const response = await fetch("http://localhost:4549/tests"); // will redirect to the same place + assertEquals(response.status, 0); // network error +}); +*/ + testPerm({ net: true }, async function fetchInitStringBody(): Promise<void> { const data = "Hello World"; const response = await fetch("http://localhost:4545/echo_server", { |