aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets
diff options
context:
space:
mode:
Diffstat (limited to 'integration/bunjs-only-snippets')
-rw-r--r--integration/bunjs-only-snippets/fetch.js17
-rw-r--r--integration/bunjs-only-snippets/fetch.test.js22
-rw-r--r--integration/bunjs-only-snippets/shadow.test.js10
-rw-r--r--integration/bunjs-only-snippets/text-encoder.test.js9
4 files changed, 41 insertions, 17 deletions
diff --git a/integration/bunjs-only-snippets/fetch.js b/integration/bunjs-only-snippets/fetch.js
deleted file mode 100644
index bb4345659..000000000
--- a/integration/bunjs-only-snippets/fetch.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import fs from "fs";
-
-const urls = ["https://example.com", "http://example.com"];
-for (let url of urls) {
- const response = await fetch(url);
- const text = await response.text();
-
- if (
- fs.readFileSync(
- import.meta.path.substring(0, import.meta.path.lastIndexOf("/")) +
- "/fetch.js.txt",
- "utf8"
- ) !== text
- ) {
- throw new Error("Expected fetch.js.txt to match snapshot");
- }
-}
diff --git a/integration/bunjs-only-snippets/fetch.test.js b/integration/bunjs-only-snippets/fetch.test.js
new file mode 100644
index 000000000..72b80cd35
--- /dev/null
+++ b/integration/bunjs-only-snippets/fetch.test.js
@@ -0,0 +1,22 @@
+import { it, describe } from "bun:test";
+import fs from "fs";
+
+describe("fetch", () => {
+ const urls = ["https://example.com", "http://example.com"];
+ for (let url of urls) {
+ it(url, async () => {
+ const response = await fetch(url);
+ const text = await response.text();
+
+ if (
+ fs.readFileSync(
+ import.meta.path.substring(0, import.meta.path.lastIndexOf("/")) +
+ "/fetch.js.txt",
+ "utf8"
+ ) !== text
+ ) {
+ throw new Error("Expected fetch.js.txt to match snapshot");
+ }
+ });
+ }
+});
diff --git a/integration/bunjs-only-snippets/shadow.test.js b/integration/bunjs-only-snippets/shadow.test.js
new file mode 100644
index 000000000..3fffcac90
--- /dev/null
+++ b/integration/bunjs-only-snippets/shadow.test.js
@@ -0,0 +1,10 @@
+import { describe, it, expect } from "bun:test";
+
+it("shadow realm works", () => {
+ const red = new ShadowRealm();
+ globalThis.someValue = 1;
+ // Affects only the ShadowRealm's global
+ const result = red.evaluate("globalThis.someValue = 2;");
+ expect(globalThis.someValue).toBe(1);
+ expect(result).toBe(2);
+});
diff --git a/integration/bunjs-only-snippets/text-encoder.test.js b/integration/bunjs-only-snippets/text-encoder.test.js
index 3b0c1f971..e4bf35059 100644
--- a/integration/bunjs-only-snippets/text-encoder.test.js
+++ b/integration/bunjs-only-snippets/text-encoder.test.js
@@ -69,6 +69,15 @@ describe("TextEncoder", () => {
}
});
+ it("should encode long latin1 text", () => {
+ const text = "Hello World!".repeat(1000);
+ const encoder = new TextEncoder();
+ const encoded = encoder.encode(text);
+ expect(encoded instanceof Uint8Array).toBe(true);
+ expect(encoded.length).toBe(text.length);
+ expect(new TextDecoder().decode(encoded)).toBe(text);
+ });
+
it("should encode latin1 rope text", () => {
var text = "Hello";
text += " ";