aboutsummaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js')
-rw-r--r--test/js/bun/util/readablestreamtoarraybuffer.test.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/js/bun/util/readablestreamtoarraybuffer.test.ts b/test/js/bun/util/readablestreamtoarraybuffer.test.ts
new file mode 100644
index 000000000..132e5f18a
--- /dev/null
+++ b/test/js/bun/util/readablestreamtoarraybuffer.test.ts
@@ -0,0 +1,29 @@
+import { test, expect } from "bun:test";
+
+test("readableStreamToArrayBuffer works", async () => {
+ // the test calls InternalPromise.then. this test ensures that such function is not user-overridable.
+ let _then = Promise.prototype.then;
+ let counter = 0;
+ // @ts-ignore
+ Promise.prototype.then = (...args) => {
+ counter++;
+ return _then.apply(this, args);
+ };
+ try {
+ const result = await Bun.readableStreamToArrayBuffer(
+ new ReadableStream({
+ async start(controller) {
+ controller.enqueue(new TextEncoder().encode("bun is"));
+ controller.enqueue(new TextEncoder().encode(" awesome!"));
+ controller.close();
+ },
+ }),
+ );
+ expect(counter).toBe(0);
+ expect(new TextDecoder().decode(result)).toBe("bun is awesome!");
+ } catch (error) {
+ throw error;
+ } finally {
+ Promise.prototype.then = _then;
+ }
+});