From a846852818278641cf33413ce784adf2fc0e2e52 Mon Sep 17 00:00:00 2001 From: dave caruso Date: Tue, 29 Aug 2023 19:45:16 -0700 Subject: 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 --- test/js/node/stream/node-stream.test.js | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/js/node/stream/node-stream.test.js') 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"); +}); -- cgit v1.2.3