diff options
author | 2022-12-15 02:25:19 -0600 | |
---|---|---|
committer | 2022-12-15 00:25:19 -0800 | |
commit | 6a1fc208354d173a66b61060ec5bb79699038006 (patch) | |
tree | ab5af3660f1ce2d8b2ac8eee154ba21221a0acd4 /test/bun.js/node-stream.test.js | |
parent | 95c747f598ff0a57335f2cb35c008132b7a3ac2b (diff) | |
download | bun-6a1fc208354d173a66b61060ec5bb79699038006.tar.gz bun-6a1fc208354d173a66b61060ec5bb79699038006.tar.zst bun-6a1fc208354d173a66b61060ec5bb79699038006.zip |
fix(stream): make Readable.read work w/o _construct implemented (#1613)
* fix(stream): put Readable._readableState.constructed default in spec (true, not false)
* cleanup(readable): remove unnecessary _construct methods
* test(stream): add test for Readable w/o _construct method
Diffstat (limited to 'test/bun.js/node-stream.test.js')
-rw-r--r-- | test/bun.js/node-stream.test.js | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/test/bun.js/node-stream.test.js b/test/bun.js/node-stream.test.js index 549f7c180..afa1867b6 100644 --- a/test/bun.js/node-stream.test.js +++ b/test/bun.js/node-stream.test.js @@ -8,18 +8,37 @@ import { } from "node:stream"; describe("Readable", () => { - it("should be able to be piped via .pipe", () => { + it("should be able to be created without _construct method defined", (done) => { const readable = new Readable({ - _read() { + read() { + this.push("Hello World!\n"); + this.push(null); + }, + }); + expect(readable instanceof Readable).toBe(true); + let data = ""; + readable.on("data", (chunk) => { + data += chunk.toString(); + }); + readable.on("end", () => { + expect(data).toBe("Hello World!\n"); + done(); + }); + }); + + it("should be able to be piped via .pipe", (done) => { + const readable = new Readable({ + read() { this.push("Hello World!"); this.push(null); }, }); const writable = new Writable({ - _write(chunk, encoding, callback) { + write(chunk, encoding, callback) { expect(chunk.toString()).toBe("Hello World!"); callback(); + done(); }, }); |