diff options
author | 2022-11-20 01:44:27 -0800 | |
---|---|---|
committer | 2022-11-20 01:44:27 -0800 | |
commit | 70f89b1bfcc751bcacf82a31682d4d1a780bba55 (patch) | |
tree | 88871f9feb229c6602e7c688204edd8e2437fd91 | |
parent | 4f5f01a74876c815f21ed82663cd31b71c9594c4 (diff) | |
download | bun-70f89b1bfcc751bcacf82a31682d4d1a780bba55.tar.gz bun-70f89b1bfcc751bcacf82a31682d4d1a780bba55.tar.zst bun-70f89b1bfcc751bcacf82a31682d4d1a780bba55.zip |
Add another test
-rw-r--r-- | test/bun.js/fetch-gzip.test.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/bun.js/fetch-gzip.test.ts b/test/bun.js/fetch-gzip.test.ts index f9b277718..f5c2ed946 100644 --- a/test/bun.js/fetch-gzip.test.ts +++ b/test/bun.js/fetch-gzip.test.ts @@ -138,6 +138,47 @@ it("fetch() with a gzip response works (one chunk)", async () => { server.stop(); }); +it("fetch() with a gzip response works (one chunk, streamed, with a delay)", async () => { + var server = Bun.serve({ + port: 6081, + + fetch(req) { + return new Response( + new ReadableStream({ + type: "direct", + async pull(controller) { + await 2; + + const buffer = await Bun.file( + import.meta.dir + "/fixture.html.gz", + ).arrayBuffer(); + controller.write(buffer); + controller.close(); + }, + }), + { + headers: { + "Content-Encoding": "gzip", + "Content-Type": "text/html; charset=utf-8", + "Content-Length": "1", + }, + }, + ); + }, + }); + + const res = await fetch(`http://${server.hostname}:${server.port}`, {}); + const arrayBuffer = await res.arrayBuffer(); + expect( + new Buffer(arrayBuffer).equals( + new Buffer( + await Bun.file(import.meta.dir + "/fixture.html").arrayBuffer(), + ), + ), + ).toBe(true); + server.stop(); +}); + it("fetch() with a gzip response works (multiple chunks)", async () => { var server = Bun.serve({ port: 6024, |