aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--integration/bunjs-only-snippets/streams.test.js42
-rw-r--r--integration/bunjs-only-snippets/web-globals.test.js30
2 files changed, 62 insertions, 10 deletions
diff --git a/integration/bunjs-only-snippets/streams.test.js b/integration/bunjs-only-snippets/streams.test.js
index 929f4a29b..59da95b5a 100644
--- a/integration/bunjs-only-snippets/streams.test.js
+++ b/integration/bunjs-only-snippets/streams.test.js
@@ -7,6 +7,8 @@ import {
import { expect, it } from "bun:test";
import { writeFileSync } from "node:fs";
+new Uint8Array();
+
it("exists globally", () => {
expect(typeof ReadableStream).toBe("function");
expect(typeof ReadableStreamBYOBReader).toBe("function");
@@ -32,12 +34,11 @@ it("ReadableStream (direct)", async () => {
cancel() {},
type: "direct",
});
- console.log("hello");
- const chunks = [];
- const chunk = await stream.getReader().read();
- console.log("it's me");
- chunks.push(chunk.value);
- expect(chunks[0].join("")).toBe(Buffer.from("helloworld").join(""));
+ var reader = stream.getReader();
+ const chunk = await reader.read();
+ expect(chunk.value.join("")).toBe(Buffer.from("helloworld").join(""));
+ expect((await reader.read()).done).toBe(true);
+ expect((await reader.read()).done).toBe(true);
});
it("ReadableStream (bytes)", async () => {
@@ -137,11 +138,27 @@ it("ReadableStream for Blob", async () => {
console.trace();
var blob = new Blob(["abdefgh", "ijklmnop"]);
expect(await blob.text()).toBe("abdefghijklmnop");
- var stream = blob.stream();
+ var stream;
+ try {
+ stream = blob.stream();
+ stream = blob.stream();
+ } catch (e) {
+ console.error(e);
+ console.error(e.stack);
+ }
const chunks = [];
- var reader = stream.getReader();
+ var reader;
+ reader = stream.getReader();
+
while (true) {
- const chunk = await reader.read();
+ var chunk;
+ try {
+ chunk = await reader.read();
+ } catch (e) {
+ console.error(e);
+ console.error(e.stack);
+ }
+
if (chunk.done) break;
chunks.push(new TextDecoder().decode(chunk.value));
}
@@ -200,7 +217,12 @@ it("ReadableStream for empty blob closes immediately", async () => {
it("ReadableStream for empty file closes immediately", async () => {
writeFileSync("/tmp/bun-empty-file-123456", "");
var blob = file("/tmp/bun-empty-file-123456");
- var stream = blob.stream();
+ var stream;
+ try {
+ stream = blob.stream();
+ } catch (e) {
+ console.error(e.stack);
+ }
const chunks = [];
var reader = stream.getReader();
while (true) {
diff --git a/integration/bunjs-only-snippets/web-globals.test.js b/integration/bunjs-only-snippets/web-globals.test.js
new file mode 100644
index 000000000..e70e823e8
--- /dev/null
+++ b/integration/bunjs-only-snippets/web-globals.test.js
@@ -0,0 +1,30 @@
+import { expect, test } from "bun:test";
+
+test("exists", () => {
+ expect(typeof URL !== "undefined").toBe(true);
+ expect(typeof URLSearchParams !== "undefined").toBe(true);
+ expect(typeof DOMException !== "undefined").toBe(true);
+ expect(typeof Event !== "undefined").toBe(true);
+ expect(typeof EventTarget !== "undefined").toBe(true);
+ expect(typeof AbortController !== "undefined").toBe(true);
+ expect(typeof AbortSignal !== "undefined").toBe(true);
+ expect(typeof CustomEvent !== "undefined").toBe(true);
+ expect(typeof Headers !== "undefined").toBe(true);
+ expect(typeof ErrorEvent !== "undefined").toBe(true);
+ expect(typeof CloseEvent !== "undefined").toBe(true);
+ expect(typeof TextEncoder !== "undefined").toBe(true);
+});
+
+test("CloseEvent", () => {
+ var event = new CloseEvent("close", { reason: "world" });
+ expect(event.type).toBe("close");
+ const target = new EventTarget();
+ var called = false;
+ target.addEventListener("close", ({ type, reason }) => {
+ expect(type).toBe("close");
+ expect(reason).toBe("world");
+ called = true;
+ });
+ target.dispatchEvent(event);
+ expect(called).toBe(true);
+});