diff options
author | 2023-08-29 19:45:16 -0700 | |
---|---|---|
committer | 2023-08-29 19:45:16 -0700 | |
commit | a846852818278641cf33413ce784adf2fc0e2e52 (patch) | |
tree | 09a92d272b78226d9d4b1b94682100428da6af3f /test/js/node/stream/node-stream.test.js | |
parent | 3f4bc625ff2313713cf38c3c3ba036781ac1c9a9 (diff) | |
download | bun-a846852818278641cf33413ce784adf2fc0e2e52.tar.gz bun-a846852818278641cf33413ce784adf2fc0e2e52.tar.zst bun-a846852818278641cf33413ce784adf2fc0e2e52.zip |
fix(node-fetch): use stream.Readable instead of web streams (#4394)
* fix blobFrom
* fix(node-fetch): use stream.Readable instead of web streams
* uncomment
* comment why
Diffstat (limited to 'test/js/node/stream/node-stream.test.js')
-rw-r--r-- | test/js/node/stream/node-stream.test.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/js/node/stream/node-stream.test.js b/test/js/node/stream/node-stream.test.js index 44f3f4ff8..bc6a4fcfb 100644 --- a/test/js/node/stream/node-stream.test.js +++ b/test/js/node/stream/node-stream.test.js @@ -314,3 +314,38 @@ it("TTY streams", () => { expect(stderr.toString()).toContain("0 fail"); expect(exitCode).toBe(0); }); + +it("Readable.toWeb", async () => { + const readable = new Readable({ + read() { + this.push("Hello "); + this.push("World!\n"); + this.push(null); + }, + }); + + const webReadable = Readable.toWeb(readable); + expect(webReadable).toBeInstanceOf(ReadableStream); + + const result = await new Response(webReadable).text(); + expect(result).toBe("Hello World!\n"); +}); + +it("Readable.fromWeb", async () => { + const readable = Readable.fromWeb( + new ReadableStream({ + start(controller) { + controller.enqueue("Hello "); + controller.enqueue("World!\n"); + controller.close(); + }, + }), + ); + expect(readable).toBeInstanceOf(Readable); + + const chunks = []; + for await (const chunk of readable) { + chunks.push(chunk); + } + expect(Buffer.concat(chunks).toString()).toBe("Hello World!\n"); +}); |