aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-01 01:33:13 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-01-01 01:33:13 -0800
commitf651f74f9d2ddb578aa2aa98f0146f17da087c23 (patch)
tree657eef147befeb9728850144651d58c1e0fafa79 /test
parent01b908ad645a32c4a7eb416f162319da19e25d2a (diff)
downloadbun-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.ts41
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");