aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/node-stream.test.js
diff options
context:
space:
mode:
authorGravatar Derrick Farris <mr.dcfarris@gmail.com> 2022-12-07 02:18:10 -0600
committerGravatar GitHub <noreply@github.com> 2022-12-07 00:18:10 -0800
commit60d0e6b73fc01896b02d83c9f845b5e12727d194 (patch)
tree14dfaa7de821430954bb357995731c383ddefb0e /test/bun.js/node-stream.test.js
parenta315ee7e0348f546179d1ec9e88e7e6b143fddc7 (diff)
downloadbun-60d0e6b73fc01896b02d83c9f845b5e12727d194.tar.gz
bun-60d0e6b73fc01896b02d83c9f845b5e12727d194.tar.zst
bun-60d0e6b73fc01896b02d83c9f845b5e12727d194.zip
fix(stream): Fix Transform class constructor fn (#1583)
* fix(stream): fix ReadableFromWeb class, fix Transform * test(stream): add tests for .call on stream constructors
Diffstat (limited to 'test/bun.js/node-stream.test.js')
-rw-r--r--test/bun.js/node-stream.test.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/bun.js/node-stream.test.js b/test/bun.js/node-stream.test.js
new file mode 100644
index 000000000..8024ab562
--- /dev/null
+++ b/test/bun.js/node-stream.test.js
@@ -0,0 +1,47 @@
+import { expect, describe, it } from "bun:test";
+import { Duplex, Transform, PassThrough } from "node:stream";
+
+describe("Duplex", () => {
+ it("should allow subclasses to be derived via .call() on class", () => {
+ function Subclass(opts) {
+ if (!(this instanceof Subclass)) return new Subclass(opts);
+ Duplex.call(this, opts);
+ }
+
+ Object.setPrototypeOf(Subclass.prototype, Duplex.prototype);
+ Object.setPrototypeOf(Subclass, Duplex);
+
+ const subclass = new Subclass();
+ expect(subclass instanceof Duplex).toBe(true);
+ });
+});
+
+describe("Transform", () => {
+ it("should allow subclasses to be derived via .call() on class", () => {
+ function Subclass(opts) {
+ if (!(this instanceof Subclass)) return new Subclass(opts);
+ Transform.call(this, opts);
+ }
+
+ Object.setPrototypeOf(Subclass.prototype, Transform.prototype);
+ Object.setPrototypeOf(Subclass, Transform);
+
+ const subclass = new Subclass();
+ expect(subclass instanceof Transform).toBe(true);
+ });
+});
+
+describe("PassThrough", () => {
+ it("should allow subclasses to be derived via .call() on class", () => {
+ function Subclass(opts) {
+ if (!(this instanceof Subclass)) return new Subclass(opts);
+ PassThrough.call(this, opts);
+ }
+
+ Object.setPrototypeOf(Subclass.prototype, PassThrough.prototype);
+ Object.setPrototypeOf(Subclass, PassThrough);
+
+ const subclass = new Subclass();
+ expect(subclass instanceof PassThrough).toBe(true);
+ });
+});