diff options
author | 2023-01-01 01:33:13 -0800 | |
---|---|---|
committer | 2023-01-01 01:33:13 -0800 | |
commit | f651f74f9d2ddb578aa2aa98f0146f17da087c23 (patch) | |
tree | 657eef147befeb9728850144651d58c1e0fafa79 /test | |
parent | 01b908ad645a32c4a7eb416f162319da19e25d2a (diff) | |
download | bun-f651f74f9d2ddb578aa2aa98f0146f17da087c23.tar.gz bun-f651f74f9d2ddb578aa2aa98f0146f17da087c23.tar.zst bun-f651f74f9d2ddb578aa2aa98f0146f17da087c23.zip |
Add a test for empty chunks
Diffstat (limited to 'test')
-rw-r--r-- | test/bun.js/serve.test.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/bun.js/serve.test.ts b/test/bun.js/serve.test.ts index 61740748d..c050e29b0 100644 --- a/test/bun.js/serve.test.ts +++ b/test/bun.js/serve.test.ts @@ -357,6 +357,47 @@ describe("streaming", () => { ); }); + it("text from JS, 3 chunks, 1 empty, with delay in pull", async () => { + const textToExpect = "hello world"; + const groups = [ + ["hello", "", " world"], + ["", "hello ", "world"], + ["hello ", "world", ""], + ["hello world", "", ""], + ["", "", "hello world"], + ]; + var count = 0; + + for (const chunks of groups) { + await runTest( + { + fetch(req) { + return new Response( + new ReadableStream({ + async pull(controller) { + for (let chunk of chunks) { + controller.enqueue(Buffer.from(chunk)); + await 1; + } + await 1; + controller.close(); + }, + }), + ); + }, + }, + async (server) => { + const response = await fetch( + `http://${server.hostname}:${server.port}`, + ); + expect(await response.text()).toBe(textToExpect); + count++; + }, + ); + } + expect(count).toBe(groups.length); + }); + it("text from JS, 2 chunks, with async pull", async () => { const fixture = resolve(import.meta.dir, "./fetch.js.txt"); const textToExpect = readFileSync(fixture, "utf-8"); |