diff options
Diffstat (limited to 'test/js')
-rw-r--r-- | test/js/node/async_hooks/async_hooks.node.test.ts | 28 | ||||
-rw-r--r-- | test/js/node/module/modulePrototypeOverwrite-fixture.cjs | 1 | ||||
-rw-r--r-- | test/js/node/module/modulePrototypeOverwrite.cjs | 17 | ||||
-rw-r--r-- | test/js/node/module/node-module-module.test.js | 11 | ||||
-rw-r--r-- | test/js/node/process/process-stdio.test.ts | 2 | ||||
-rw-r--r-- | test/js/node/stream/node-stream.test.js | 12 | ||||
-rwxr-xr-x | test/js/third_party/got/bun.lockb | bin | 0 -> 9072 bytes | |||
-rwxr-xr-x | test/js/third_party/prisma/bun.lockb | bin | 0 -> 2951 bytes | |||
-rwxr-xr-x | test/js/third_party/yargs/bun.lockb | bin | 0 -> 6747 bytes |
9 files changed, 62 insertions, 9 deletions
diff --git a/test/js/node/async_hooks/async_hooks.node.test.ts b/test/js/node/async_hooks/async_hooks.node.test.ts index 3d6183948..5fc56a39b 100644 --- a/test/js/node/async_hooks/async_hooks.node.test.ts +++ b/test/js/node/async_hooks/async_hooks.node.test.ts @@ -1,13 +1,13 @@ -import { AsyncLocalStorage } from "async_hooks"; +import { AsyncLocalStorage, AsyncResource } from "async_hooks"; import assert from "assert"; test("node async_hooks.AsyncLocalStorage enable disable", async done => { - const asyncLocalStorage = new AsyncLocalStorage(); + const asyncLocalStorage = new AsyncLocalStorage<Map<string, any>>(); asyncLocalStorage.run(new Map(), () => { - asyncLocalStorage.getStore().set("foo", "bar"); + asyncLocalStorage.getStore()!.set("foo", "bar"); process.nextTick(() => { - assert.strictEqual(asyncLocalStorage.getStore().get("foo"), "bar"); + assert.strictEqual(asyncLocalStorage.getStore()!.get("foo"), "bar"); process.nextTick(() => { assert.strictEqual(asyncLocalStorage.getStore(), undefined); }); @@ -24,7 +24,7 @@ test("node async_hooks.AsyncLocalStorage enable disable", async done => { process.nextTick(() => { assert.strictEqual(asyncLocalStorage.getStore(), undefined); asyncLocalStorage.run(new Map().set("bar", "foo"), () => { - assert.strictEqual(asyncLocalStorage.getStore().get("bar"), "foo"); + assert.strictEqual(asyncLocalStorage.getStore()!.get("bar"), "foo"); done(); }); @@ -32,3 +32,21 @@ test("node async_hooks.AsyncLocalStorage enable disable", async done => { }); }); }); + +test("AsyncResource.prototype.bind", () => { + const localStorage = new AsyncLocalStorage<true>(); + let ar!: AsyncResource; + localStorage.run(true, () => { + ar = new AsyncResource("test"); + }); + expect(ar.bind(() => localStorage.getStore())()).toBe(true); +}); + +test("AsyncResource.bind", () => { + const localStorage = new AsyncLocalStorage<true>(); + let fn!: () => true | undefined; + localStorage.run(true, () => { + fn = AsyncResource.bind(() => localStorage.getStore()); + }); + expect(fn()).toBe(true); +}); diff --git a/test/js/node/module/modulePrototypeOverwrite-fixture.cjs b/test/js/node/module/modulePrototypeOverwrite-fixture.cjs new file mode 100644 index 000000000..eecab81c1 --- /dev/null +++ b/test/js/node/module/modulePrototypeOverwrite-fixture.cjs @@ -0,0 +1 @@ +module.exports = require("hook"); diff --git a/test/js/node/module/modulePrototypeOverwrite.cjs b/test/js/node/module/modulePrototypeOverwrite.cjs new file mode 100644 index 000000000..4e84026a6 --- /dev/null +++ b/test/js/node/module/modulePrototypeOverwrite.cjs @@ -0,0 +1,17 @@ +// This behavior is required for Next.js to work +const eql = require("assert").deepStrictEqual; +const Module = require("module"); + +const old = Module.prototype.require; +Module.prototype.require = function (str) { + if (str === "hook") return "winner"; + return { + wrap: old.call(this, str), + }; +}; + +// this context has the new require +const result = require("./modulePrototypeOverwrite-fixture.cjs"); +eql(result, { wrap: "winner" }); + +console.log("--pass--"); diff --git a/test/js/node/module/node-module-module.test.js b/test/js/node/module/node-module-module.test.js index 26fbb6fab..5ac48d426 100644 --- a/test/js/node/module/node-module-module.test.js +++ b/test/js/node/module/node-module-module.test.js @@ -71,6 +71,17 @@ test("Overwriting _resolveFilename", () => { expect(exitCode).toBe(0); }); +test("Overwriting Module.prototype.require", () => { + const { stdout, exitCode } = Bun.spawnSync({ + cmd: [bunExe(), "run", path.join(import.meta.dir, "modulePrototypeOverwrite.cjs")], + env: bunEnv, + stderr: "inherit", + }); + + expect(stdout.toString().trim().endsWith("--pass--")).toBe(true); + expect(exitCode).toBe(0); +}); + test("Module.prototype._compile", () => { const module = new Module("module id goes here"); const starting_exports = module.exports; diff --git a/test/js/node/process/process-stdio.test.ts b/test/js/node/process/process-stdio.test.ts index 463ab5fda..5349587af 100644 --- a/test/js/node/process/process-stdio.test.ts +++ b/test/js/node/process/process-stdio.test.ts @@ -5,7 +5,7 @@ import { isatty } from "tty"; test("process.stdin", () => { expect(process.stdin).toBeDefined(); - expect(process.stdout.isTTY).toBe(isatty(0)); + expect(process.stdin.isTTY).toBe(isatty(0) ? true : undefined); expect(process.stdin.on("close", function () {})).toBe(process.stdin); expect(process.stdin.once("end", function () {})).toBe(process.stdin); }); diff --git a/test/js/node/stream/node-stream.test.js b/test/js/node/stream/node-stream.test.js index bc6a4fcfb..ddbd2bc7a 100644 --- a/test/js/node/stream/node-stream.test.js +++ b/test/js/node/stream/node-stream.test.js @@ -197,6 +197,7 @@ describe("PassThrough", () => { const ttyStreamsTest = ` import tty from "tty"; +import fs from "fs"; import { dlopen } from "bun:ffi"; @@ -278,10 +279,11 @@ describe("TTY", () => { close(child_fd); }); it("process.stdio tty", () => { - expect(process.stdin instanceof tty.ReadStream).toBe(true); + // this isnt run in a tty, so stdin will not appear to be a tty + expect(process.stdin instanceof fs.ReadStream).toBe(true); expect(process.stdout instanceof tty.WriteStream).toBe(true); expect(process.stderr instanceof tty.WriteStream).toBe(true); - expect(process.stdin.isTTY).toBeDefined(); + expect(process.stdin.isTTY).toBeUndefined(); expect(process.stdout.isTTY).toBeDefined(); expect(process.stderr.isTTY).toBeDefined(); }); @@ -311,7 +313,11 @@ it("TTY streams", () => { }); expect(stdout.toString()).toBe(""); - expect(stderr.toString()).toContain("0 fail"); + try { + expect(stderr.toString()).toContain("0 fail"); + } catch (error) { + throw new Error(stderr.toString()); + } expect(exitCode).toBe(0); }); diff --git a/test/js/third_party/got/bun.lockb b/test/js/third_party/got/bun.lockb Binary files differnew file mode 100755 index 000000000..7dbe60317 --- /dev/null +++ b/test/js/third_party/got/bun.lockb diff --git a/test/js/third_party/prisma/bun.lockb b/test/js/third_party/prisma/bun.lockb Binary files differnew file mode 100755 index 000000000..65d0238e5 --- /dev/null +++ b/test/js/third_party/prisma/bun.lockb diff --git a/test/js/third_party/yargs/bun.lockb b/test/js/third_party/yargs/bun.lockb Binary files differnew file mode 100755 index 000000000..6b527d00f --- /dev/null +++ b/test/js/third_party/yargs/bun.lockb |