diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/flash_test.ts | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/cli/tests/unit/flash_test.ts b/cli/tests/unit/flash_test.ts index 9491e4534..5604f6b5f 100644 --- a/cli/tests/unit/flash_test.ts +++ b/cli/tests/unit/flash_test.ts @@ -12,6 +12,7 @@ import { assert, assertEquals, assertRejects, + assertStringIncludes, assertThrows, Deferred, deferred, @@ -495,6 +496,51 @@ Deno.test( }, ); +// https://github.com/denoland/deno/issues/17291 +Deno.test( + { permissions: { net: true } }, + async function httpServerIncorrectChunkedResponse() { + const ac = new AbortController(); + const listeningPromise = deferred(); + const errorPromise = deferred(); + const server = Deno.serve({ + handler: () => { + const body = new ReadableStream({ + start(controller) { + // Non-encoded string is not a valid readable chunk. + controller.enqueue("wat"); + }, + }); + return new Response(body); + }, + port: 4501, + signal: ac.signal, + onListen: onListen(listeningPromise), + onError: (err) => { + const errResp = new Response( + `Internal server error: ${(err as Error).message}`, + { status: 500 }, + ); + ac.abort(); + errorPromise.resolve(errResp); + return errResp; + }, + }); + + await listeningPromise; + + const resp = await fetch("http://127.0.0.1:4501/"); + // Incorrectly implemented reader ReadableStream should reject. + await assertRejects(() => resp.body!.getReader().read()); + + const err = await errorPromise as Response; + assertStringIncludes(await err.text(), "Expected ArrayBufferView"); + + ac.abort(); + await server; + }, +); + Deno.test( { permissions: { net: true } }, async function httpServerCorrectLengthForUnicodeString() { |