diff options
Diffstat (limited to 'cli/tests/unit/fetch_test.ts')
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index c93cc0c85..9562c48c7 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -16,7 +16,7 @@ unitTest({ perms: { net: true } }, async function fetchProtocolError(): Promise< await fetch("file:///"); }, TypeError, - "not supported" + "not supported", ); }); @@ -28,9 +28,9 @@ unitTest( await fetch("http://localhost:4000"); }, Deno.errors.Http, - "error trying to connect" + "error trying to connect", ); - } + }, ); unitTest({ perms: { net: true } }, async function fetchJsonSuccess(): Promise< @@ -55,7 +55,7 @@ unitTest({ perms: { net: true } }, async function fetchUrl(): Promise<void> { unitTest({ perms: { net: true } }, async function fetchURL(): Promise<void> { const response = await fetch( - new URL("http://localhost:4545/cli/tests/fixture.json") + new URL("http://localhost:4545/cli/tests/fixture.json"), ); assertEquals(response.url, "http://localhost:4545/cli/tests/fixture.json"); const _json = await response.json(); @@ -95,7 +95,7 @@ unitTest( { perms: { net: true } }, async function fetchBodyUsedReader(): Promise<void> { const response = await fetch( - "http://localhost:4545/cli/tests/fixture.json" + "http://localhost:4545/cli/tests/fixture.json", ); assert(response.body !== null); @@ -106,14 +106,14 @@ unitTest( reader.releaseLock(); await response.json(); assertEquals(response.bodyUsed, true); - } + }, ); unitTest( { perms: { net: true } }, async function fetchBodyUsedCancelStream(): Promise<void> { const response = await fetch( - "http://localhost:4545/cli/tests/fixture.json" + "http://localhost:4545/cli/tests/fixture.json", ); assert(response.body !== null); @@ -121,7 +121,7 @@ unitTest( const promise = response.body.cancel(); assertEquals(response.bodyUsed, true); await promise; - } + }, ); unitTest({ perms: { net: true } }, async function fetchAsyncIterator(): Promise< @@ -176,7 +176,7 @@ unitTest( } assertEquals(total, data.length); - } + }, ); unitTest({ perms: { net: true } }, async function responseClone(): Promise< @@ -206,7 +206,7 @@ unitTest( { perms: { net: true } }, async function fetchMultipartFormDataSuccess(): Promise<void> { const response = await fetch( - "http://localhost:4545/multipart_form_data.txt" + "http://localhost:4545/multipart_form_data.txt", ); const formData = await response.formData(); assert(formData.has("field_1")); @@ -216,28 +216,28 @@ unitTest( assertEquals(file.name, "file.js"); assertEquals(await file.text(), `console.log("Hi")`); - } + }, ); unitTest( { perms: { net: true } }, async function fetchURLEncodedFormDataSuccess(): Promise<void> { const response = await fetch( - "http://localhost:4545/cli/tests/subdir/form_urlencoded.txt" + "http://localhost:4545/cli/tests/subdir/form_urlencoded.txt", ); const formData = await response.formData(); assert(formData.has("field_1")); assertEquals(formData.get("field_1")!.toString(), "Hi"); assert(formData.has("field_2")); assertEquals(formData.get("field_2")!.toString(), "<Deno>"); - } + }, ); unitTest( { perms: { net: true } }, async function fetchInitFormDataBinaryFileBody(): Promise<void> { // Some random bytes - // prettier-ignore + // deno-fmt-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", @@ -249,7 +249,7 @@ unitTest( assertEquals(resultFile.type, "application/octet-stream"); assertEquals(resultFile.name, "file.bin"); assertEquals(new Uint8Array(await resultFile.arrayBuffer()), binaryFile); - } + }, ); unitTest( @@ -257,14 +257,14 @@ unitTest( async function fetchInitFormDataMultipleFilesBody(): Promise<void> { const files = [ { - // prettier-ignore + // deno-fmt-ignore content: new Uint8Array([137,80,78,71,13,10,26,10, 137, 1, 25]), type: "image/png", name: "image", fileName: "some-image.png", }, { - // prettier-ignore + // deno-fmt-ignore content: new Uint8Array([108,2,0,0,145,22,162,61,157,227,166,77,138,75,180,56,119,188,177,183]), name: "file", fileName: "file.bin", @@ -283,7 +283,7 @@ unitTest( form.append( file.name, new Blob([file.content], { type: file.type }), - file.fileName + file.fileName, ); } const response = await fetch("http://localhost:4545/echo_server", { @@ -300,10 +300,10 @@ unitTest( assertEquals(file.expectedType || file.type, resultFile.type); assertEquals( new Uint8Array(await resultFile.arrayBuffer()), - file.content + file.content, ); } - } + }, ); unitTest( @@ -317,7 +317,7 @@ unitTest( assertEquals(response.url, "http://localhost:4545/README.md"); const body = await response.text(); assert(body.includes("Deno")); - } + }, ); unitTest( @@ -326,13 +326,13 @@ unitTest( }, async function fetchWithRelativeRedirection(): Promise<void> { const response = await fetch( - "http://localhost:4545/cli/tests/001_hello.js" + "http://localhost:4545/cli/tests/001_hello.js", ); assertEquals(response.status, 200); assertEquals(response.statusText, "OK"); const body = await response.text(); assert(body.includes("Hello")); - } + }, ); unitTest( @@ -353,7 +353,7 @@ unitTest( assertEquals(response.status, 404); assertEquals(await response.text(), ""); } - } + }, ); unitTest( @@ -365,7 +365,7 @@ unitTest( assertEquals(response.status, 0); // network error assertEquals(response.type, "error"); assertEquals(response.ok, false); - } + }, ); unitTest( @@ -379,7 +379,7 @@ unitTest( const text = await response.text(); assertEquals(text, data); assert(response.headers.get("content-type")!.startsWith("text/plain")); - } + }, ); unitTest( @@ -393,7 +393,7 @@ unitTest( const response = await fetch(req); const text = await response.text(); assertEquals(text, data); - } + }, ); unitTest( @@ -406,7 +406,7 @@ unitTest( }); const text = await response.text(); assertEquals(text, data); - } + }, ); unitTest( @@ -419,7 +419,7 @@ unitTest( }); const text = await response.text(); assertEquals(text, data); - } + }, ); unitTest( @@ -436,9 +436,9 @@ unitTest( assert( response.headers .get("content-type")! - .startsWith("application/x-www-form-urlencoded") + .startsWith("application/x-www-form-urlencoded"), ); - } + }, ); unitTest({ perms: { net: true } }, async function fetchInitBlobBody(): Promise< @@ -468,7 +468,7 @@ unitTest( }); const resultForm = await response.formData(); assertEquals(form.get("field"), resultForm.get("field")); - } + }, ); unitTest( @@ -486,7 +486,7 @@ unitTest( const file = resultForm.get("file"); assert(file instanceof File); assertEquals(file.name, "blob"); - } + }, ); unitTest( @@ -500,7 +500,7 @@ unitTest( new Blob([new TextEncoder().encode(fileContent)], { type: "text/plain", }), - "deno.txt" + "deno.txt", ); const response = await fetch("http://localhost:4545/echo_server", { method: "POST", @@ -516,7 +516,7 @@ unitTest( assertEquals(file.name, resultFile.name); assertEquals(file.type, resultFile.type); assertEquals(await file.text(), await resultFile.text()); - } + }, ); unitTest({ perms: { net: true } }, async function fetchUserAgent(): Promise< @@ -561,8 +561,8 @@ function bufferServer(addr: string): Deno.Buffer { const p1 = buf.readFrom(conn); const p2 = conn.write( new TextEncoder().encode( - "HTTP/1.0 404 Not Found\r\nContent-Length: 2\r\n\r\nNF" - ) + "HTTP/1.0 404 Not Found\r\nContent-Length: 2\r\n\r\nNF", + ), ); // Wait for both an EOF on the read side of the socket and for the write to // complete before closing it. Due to keep-alive, the EOF won't be sent @@ -606,7 +606,7 @@ unitTest( `host: ${addr}\r\n\r\n`, ].join(""); assertEquals(actual, expected); - } + }, ); unitTest( @@ -643,7 +643,7 @@ unitTest( body, ].join(""); assertEquals(actual, expected); - } + }, ); unitTest( @@ -680,7 +680,7 @@ unitTest( bodyStr, ].join(""); assertEquals(actual, expected); - } + }, ); unitTest( @@ -698,12 +698,12 @@ unitTest( try { await response.text(); fail( - "Reponse.text() didn't throw on a filtered response without a body (type opaqueredirect)" + "Reponse.text() didn't throw on a filtered response without a body (type opaqueredirect)", ); } catch (e) { return; } - } + }, ); unitTest( @@ -721,12 +721,12 @@ unitTest( try { await response.text(); fail( - "Reponse.text() didn't throw on a filtered response without a body (type error)" + "Reponse.text() didn't throw on a filtered response without a body (type error)", ); } catch (e) { return; } - } + }, ); unitTest(function responseRedirect(): void { @@ -753,7 +753,7 @@ unitTest({ perms: { net: true } }, async function fetchBodyReadTwice(): Promise< try { await response[method](); fail( - "Reading body multiple times should failed, the stream should've been locked." + "Reading body multiple times should failed, the stream should've been locked.", ); } catch { // pass @@ -765,7 +765,7 @@ unitTest( { perms: { net: true } }, async function fetchBodyReaderAfterRead(): Promise<void> { const response = await fetch( - "http://localhost:4545/cli/tests/fixture.json" + "http://localhost:4545/cli/tests/fixture.json", ); assert(response.body !== null); const reader = await response.body.getReader(); @@ -781,7 +781,7 @@ unitTest( } catch { // pass } - } + }, ); unitTest( @@ -809,7 +809,7 @@ unitTest( } assertEquals(total, data.length); - } + }, ); unitTest( @@ -839,7 +839,7 @@ unitTest( total += value.length; } assertEquals(total, data.length); - } + }, ); unitTest( @@ -851,7 +851,7 @@ unitTest( // After ReadableStream.cancel is called, resource handle must be closed // The test should not fail with: Test case is leaking resources await res.body.cancel(); - } + }, ); unitTest( @@ -869,7 +869,7 @@ unitTest( assertEquals(res.body, null); assertEquals(res.status, status); } - } + }, ); unitTest( @@ -888,7 +888,7 @@ unitTest( // Make sure Body content-type is correctly set assertEquals(blob.type, "application/octet-stream"); assertEquals(blob.size, body.byteLength); - } + }, ); unitTest(function fetchResponseConstructorNullBody(): void { @@ -902,7 +902,7 @@ unitTest(function fetchResponseConstructorNullBody(): void { assert(e instanceof TypeError); assertEquals( e.message, - "Response with null body status cannot have body" + "Response with null body status cannot have body", ); } } @@ -921,7 +921,7 @@ unitTest(function fetchResponseConstructorInvalidStatus(): void { assert(e instanceof RangeError); assertEquals( e.message, - `The status provided (${status}) is outside the range [200, 599]` + `The status provided (${status}) is outside the range [200, 599]`, ); } } |