diff options
author | 2022-02-24 00:59:19 -0800 | |
---|---|---|
committer | 2022-02-24 00:59:19 -0800 | |
commit | 8effa394100b26805cc9ca298659f1a5a7c3dda9 (patch) | |
tree | 54fda1f4ab7b8d901c984d25b8d1c3c407a0349b /integration/bunjs-only-snippets | |
parent | 5f50de2b390ef1ddfe2e108d285024ef45d4c421 (diff) | |
download | bun-8effa394100b26805cc9ca298659f1a5a7c3dda9.tar.gz bun-8effa394100b26805cc9ca298659f1a5a7c3dda9.tar.zst bun-8effa394100b26805cc9ca298659f1a5a7c3dda9.zip |
[bun.js] Add `ShadowRealm`
Diffstat (limited to 'integration/bunjs-only-snippets')
-rw-r--r-- | integration/bunjs-only-snippets/fetch.js | 17 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/fetch.test.js | 22 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/shadow.test.js | 10 | ||||
-rw-r--r-- | integration/bunjs-only-snippets/text-encoder.test.js | 9 |
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 += " "; |