From 1d3dce9a68c981aded31b4eb12f8a2ec4beecfab Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Mon, 1 Jun 2020 14:32:08 +0200 Subject: fix(cli/js/web): formData parser for binary files (#6015) --- cli/tests/unit/fetch_test.ts | 19 +++++++++++++++++++ 1 file changed, 19 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 c1dde92a9..57414d652 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -216,6 +216,25 @@ unitTest( } ); +unitTest( + { perms: { net: true } }, + async function fetchInitFormDataBinaryFileBody(): Promise { + // Some random bytes + // prettier-ignore + const binaryFile = new Uint8Array([108,2,0,0,145,22,162,61,157,227,166,77,138,75,180,56,119,188,177,183]); + const response = await fetch("http://localhost:4545/echo_multipart_file", { + method: "POST", + body: binaryFile, + }); + const resultForm = await response.formData(); + const resultFile = resultForm.get("file") as File; + + assertEquals(resultFile.type, "application/octet-stream"); + assertEquals(resultFile.name, "file.bin"); + assertEquals(new Uint8Array(await resultFile.arrayBuffer()), binaryFile); + } +); + unitTest( { perms: { net: true }, -- cgit v1.2.3