diff options
author | 2023-09-14 00:39:36 -0400 | |
---|---|---|
committer | 2023-09-13 21:39:36 -0700 | |
commit | 9976e3f528bae74667a2f4742c4b165b7f68c76d (patch) | |
tree | eb4a123f5c533f73559f894bff77d5db65906a56 /test/js | |
parent | fbafbd3394a2c1a1112df148fa2b151ee0955cc5 (diff) | |
download | bun-9976e3f528bae74667a2f4742c4b165b7f68c76d.tar.gz bun-9976e3f528bae74667a2f4742c4b165b7f68c76d.tar.zst bun-9976e3f528bae74667a2f4742c4b165b7f68c76d.zip |
fix(runtime): make most globals configurable/deletable, allow resuming the console iterator (#5216)
* Fix #5177
* Fix #5175
* make most globals deletable/overridable
* not done
* cool
* a
* done
* fix test
* oops
* yippee
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/bun/console/console-iterator-run-2.ts | 16 | ||||
-rw-r--r-- | test/js/bun/console/console-iterator-run.ts (renamed from test/js/bun/console/console-iterator-run.js) | 0 | ||||
-rw-r--r-- | test/js/bun/console/console-iterator.test.ts (renamed from test/js/bun/console/console-iterator.test.js) | 23 | ||||
-rw-r--r-- | test/js/bun/deletable-globals-fixture.js | 10 | ||||
-rw-r--r-- | test/js/bun/globals.test.js | 22 |
5 files changed, 69 insertions, 2 deletions
diff --git a/test/js/bun/console/console-iterator-run-2.ts b/test/js/bun/console/console-iterator-run-2.ts new file mode 100644 index 000000000..dba658821 --- /dev/null +++ b/test/js/bun/console/console-iterator-run-2.ts @@ -0,0 +1,16 @@ +async function readInput() { + let items = []; + for await (const line of console) { + if (line == "break") { + break; + } + items.push(line); + } + return items; +} + +const a = await readInput(); +console.write(JSON.stringify(a)); + +const b = await readInput(); +console.write(JSON.stringify(b)); diff --git a/test/js/bun/console/console-iterator-run.js b/test/js/bun/console/console-iterator-run.ts index 7664c85a1..7664c85a1 100644 --- a/test/js/bun/console/console-iterator-run.js +++ b/test/js/bun/console/console-iterator-run.ts diff --git a/test/js/bun/console/console-iterator.test.js b/test/js/bun/console/console-iterator.test.ts index 89894fd72..6c1062544 100644 --- a/test/js/bun/console/console-iterator.test.js +++ b/test/js/bun/console/console-iterator.test.ts @@ -16,7 +16,7 @@ describe("should work for static input", () => { for (let input of inputs) { it(input.replaceAll("\n", "\\n"), () => { const { stdout } = spawnSync({ - cmd: [bunExe(), import.meta.dir + "/" + "console-iterator-run.js"], + cmd: [bunExe(), import.meta.dir + "/" + "console-iterator-run.ts"], stdin: Buffer.from(input), env: { BUN_DEBUG_QUIET_LOGS: "1", @@ -41,7 +41,7 @@ describe("should work for streaming input", () => { for (let input of inputs) { it(input.replaceAll("\n", "\\n"), async () => { const proc = spawn({ - cmd: [bunExe(), import.meta.dir + "/" + "console-iterator-run.js"], + cmd: [bunExe(), import.meta.dir + "/" + "console-iterator-run.ts"], stdin: "pipe", stdout: "pipe", env: { @@ -61,3 +61,22 @@ describe("should work for streaming input", () => { }); } }); + +// https://github.com/oven-sh/bun/issues/5175 +it("can use the console iterator more than once", async () => { + const proc = spawn({ + cmd: [bunExe(), import.meta.dir + "/" + "console-iterator-run-2.ts"], + stdin: "pipe", + stdout: "pipe", + env: { + BUN_DEBUG_QUIET_LOGS: "1", + }, + }); + const { stdout, stdin } = proc; + stdin.write("hello\nworld\nbreak\nanother\nbreak\n"); + stdin.flush(); + stdin.end(); + + expect(await new Response(stdout).text()).toBe('["hello","world"]["another"]'); + proc.kill(0); +}); diff --git a/test/js/bun/deletable-globals-fixture.js b/test/js/bun/deletable-globals-fixture.js new file mode 100644 index 000000000..b67b9ac43 --- /dev/null +++ b/test/js/bun/deletable-globals-fixture.js @@ -0,0 +1,10 @@ +const { ok, strictEqual: eql } = require("assert"); + +const globals = ["Blob", "fetch", "Headers", "Request", "Response", "setTimeout", "clearTimeout", "setInterval"]; +for (let name of globals) { + ok(delete globalThis[name]); + eql(globalThis[name], undefined); + globalThis[name] = 123; + eql(globalThis[name], 123); +} +console.log("--pass--"); diff --git a/test/js/bun/globals.test.js b/test/js/bun/globals.test.js index fd291d8bc..3dd129e6a 100644 --- a/test/js/bun/globals.test.js +++ b/test/js/bun/globals.test.js @@ -1,4 +1,6 @@ import { expect, it, describe } from "bun:test"; +import { bunEnv, bunExe } from "harness"; +import path from "path"; it("extendable", () => { const classes = [Blob, TextDecoder, TextEncoder, Request, Response, Headers, HTMLRewriter, Bun.Transpiler, Buffer]; @@ -123,3 +125,23 @@ describe("File", () => { expect(await foo.text()).toBe("foo"); }); }); + +it("globals are deletable", () => { + const { stdout, exitCode } = Bun.spawnSync({ + cmd: [bunExe(), "run", path.join(import.meta.dir, "deletable-globals-fixture.js")], + env: bunEnv, + stderr: "inherit", + }); + + expect(stdout.toString().trim().endsWith("--pass--")).toBe(true); + expect(exitCode).toBe(0); +}); + +it("self is a getter", () => { + const descriptor = Object.getOwnPropertyDescriptor(globalThis, "self"); + expect(descriptor.get).toBeInstanceOf(Function); + expect(descriptor.set).toBeInstanceOf(Function); + expect(descriptor.enumerable).toBe(true); + expect(descriptor.configurable).toBe(true); + expect(globalThis.self).toBe(globalThis); +}); |