From 29db4104c4b05d7eff3a5d74514db0904ea1cd98 Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Mon, 1 Jun 2020 14:37:46 +0200 Subject: fix(cli/web): Body.bodyUsed should use IsReadableStreamDisturbed --- cli/tests/unit/fetch_test.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'cli/tests/unit/fetch_test.ts') diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 57414d652..554cf31e9 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -100,6 +100,39 @@ unitTest({ perms: { net: true } }, async function fetchBodyUsed(): Promise< assertEquals(response.bodyUsed, true); }); +unitTest( + { perms: { net: true } }, + async function fetchBodyUsedReader(): Promise { + const response = await fetch( + "http://localhost:4545/cli/tests/fixture.json" + ); + assert(response.body !== null); + + const reader = response.body.getReader(); + // Getting a reader should lock the stream but does not consume the body + // so bodyUsed should not be true + assertEquals(response.bodyUsed, false); + reader.releaseLock(); + await response.json(); + assertEquals(response.bodyUsed, true); + } +); + +unitTest( + { perms: { net: true } }, + async function fetchBodyUsedCancelStream(): Promise { + const response = await fetch( + "http://localhost:4545/cli/tests/fixture.json" + ); + assert(response.body !== null); + + assertEquals(response.bodyUsed, false); + const promise = response.body.cancel(); + assertEquals(response.bodyUsed, true); + await promise; + } +); + unitTest({ perms: { net: true } }, async function fetchAsyncIterator(): Promise< void > { -- cgit v1.2.3