From 89ebe2079bf51ec55c89c093ab16c3179ccd43fe Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Sun, 28 Jun 2020 16:31:56 +0200 Subject: fix(cli/body): Maximum call stack size exceeded error (#6537) --- cli/tests/unit/body_test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'cli/tests/unit') diff --git a/cli/tests/unit/body_test.ts b/cli/tests/unit/body_test.ts index df824e1ae..d0423f7de 100644 --- a/cli/tests/unit/body_test.ts +++ b/cli/tests/unit/body_test.ts @@ -79,3 +79,26 @@ unitTest({ perms: {} }, async function bodyURLSearchParams(): Promise { const text = await body.text(); assertEquals(text, "hello=world"); }); + +unitTest(async function bodyArrayBufferMultipleParts(): Promise { + const parts: Uint8Array[] = []; + let size = 0; + for (let i = 0; i <= 150000; i++) { + const part = new Uint8Array([1]); + parts.push(part); + size += part.length; + } + + let offset = 0; + const stream = new ReadableStream({ + pull(controller): void { + // parts.shift() takes forever: https://github.com/denoland/deno/issues/5259 + const chunk = parts[offset++]; + if (!chunk) return controller.close(); + controller.enqueue(chunk); + }, + }); + + const body = buildBody(stream); + assertEquals((await body.arrayBuffer()).byteLength, size); +}); -- cgit v1.2.3