From aa2db4abd50dee0dacf5318d3dca1fe8d508a43e Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Mon, 27 Jul 2026 18:19:13 +0000 Subject: [PATCH 1/4] test: replace vacuous jest-globals scoping test with a real one The "Jest's globals aren't available in every file" test imported the jest-doesnt-auto-import.js fixture and then asserted `typeof jestGlobals.describe === "undefined"` on the module namespace object. The fixture only ever exported `getJestGlobals` (a function), never `describe`/`it`/etc., so every assertion read a nonexistent property and passed unconditionally. The test could not fail. Calling `getJestGlobals()` instead would have made it fail: #17734 intentionally made `inject_jest_globals` apply to every file loaded by `bun test` (fixing #12034), so the original premise (non-entrypoint files under `bun test` don't get the globals) no longer holds by design. The vacuous test simply never caught the behaviour change. Replace it with a test for the scoping guarantee that does still hold: ordinary `bun` / `bun -e` runs do not inject the jest globals. Delete the fixture, whose name is now actively misleading. --- test/js/bun/test/jest-doesnt-auto-import.js | 12 ------- .../test-auto-import-jest-globals.test.js | 32 ++++++++++++------- 2 files changed, 21 insertions(+), 23 deletions(-) delete mode 100644 test/js/bun/test/jest-doesnt-auto-import.js diff --git a/test/js/bun/test/jest-doesnt-auto-import.js b/test/js/bun/test/jest-doesnt-auto-import.js deleted file mode 100644 index 4d4a02b37378..000000000000 --- a/test/js/bun/test/jest-doesnt-auto-import.js +++ /dev/null @@ -1,12 +0,0 @@ -export function getJestGlobals() { - return { - describe: typeof describe === "function" ? describe : undefined, - it: typeof it === "function" ? it : undefined, - test: typeof test === "function" ? test : undefined, - expect: typeof expect === "function" ? expect : undefined, - beforeAll: typeof beforeAll === "function" ? beforeAll : undefined, - beforeEach: typeof beforeEach === "function" ? beforeEach : undefined, - afterAll: typeof afterAll === "function" ? afterAll : undefined, - afterEach: typeof afterEach === "function" ? afterEach : undefined, - }; -} diff --git a/test/js/bun/test/test-auto-import-jest-globals.test.js b/test/js/bun/test/test-auto-import-jest-globals.test.js index 5baeae43e917..90efe9455b46 100644 --- a/test/js/bun/test/test-auto-import-jest-globals.test.js +++ b/test/js/bun/test/test-auto-import-jest-globals.test.js @@ -1,3 +1,5 @@ +import { bunEnv, bunExe } from "harness"; + test("Jest auto imports", () => { expect(true).toBe(true); expect(typeof describe).toBe("function"); @@ -10,15 +12,23 @@ test("Jest auto imports", () => { expect(typeof afterEach).toBe("function"); }); -test("Jest's globals aren't available in every file", async () => { - const jestGlobals = await import("./jest-doesnt-auto-import.js"); - - expect(typeof jestGlobals.describe).toBe("undefined"); - expect(typeof jestGlobals.it).toBe("undefined"); - expect(typeof jestGlobals.test).toBe("undefined"); - expect(typeof jestGlobals.expect).toBe("undefined"); - expect(typeof jestGlobals.beforeAll).toBe("undefined"); - expect(typeof jestGlobals.beforeEach).toBe("undefined"); - expect(typeof jestGlobals.afterAll).toBe("undefined"); - expect(typeof jestGlobals.afterEach).toBe("undefined"); +// Injection is a `bun test`-mode parser transform (#17734 made it apply to every +// file loaded by the test runner, not just the entrypoint). The only remaining +// scoping guarantee is that ordinary `bun ` / `bun -e` runs do NOT see it. +test("Jest globals are not injected outside of `bun test`", async () => { + const names = ["describe", "it", "test", "expect", "beforeAll", "beforeEach", "afterAll", "afterEach"]; + await using proc = Bun.spawn({ + cmd: [ + bunExe(), + "-e", + `process.stdout.write(JSON.stringify({${names.map(n => `${n}: typeof ${n}`).join(", ")}}))`, + ], + env: bunEnv, + stdout: "pipe", + stderr: "pipe", + }); + const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + expect(stderr).toBe(""); + expect(JSON.parse(stdout)).toEqual(Object.fromEntries(names.map(n => [n, "undefined"]))); + expect(exitCode).toBe(0); }); From 04c3bb50e777c97bdd1873e904baf55b68587b4b Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2026 18:21:37 +0000 Subject: [PATCH 2/4] [autofix.ci] apply automated fixes --- test/js/bun/test/test-auto-import-jest-globals.test.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/js/bun/test/test-auto-import-jest-globals.test.js b/test/js/bun/test/test-auto-import-jest-globals.test.js index 90efe9455b46..b68574ea2173 100644 --- a/test/js/bun/test/test-auto-import-jest-globals.test.js +++ b/test/js/bun/test/test-auto-import-jest-globals.test.js @@ -18,11 +18,7 @@ test("Jest auto imports", () => { test("Jest globals are not injected outside of `bun test`", async () => { const names = ["describe", "it", "test", "expect", "beforeAll", "beforeEach", "afterAll", "afterEach"]; await using proc = Bun.spawn({ - cmd: [ - bunExe(), - "-e", - `process.stdout.write(JSON.stringify({${names.map(n => `${n}: typeof ${n}`).join(", ")}}))`, - ], + cmd: [bunExe(), "-e", `process.stdout.write(JSON.stringify({${names.map(n => `${n}: typeof ${n}`).join(", ")}}))`], env: bunEnv, stdout: "pipe", stderr: "pipe", From 466796084bf21c162dcb7d7dfa9a4a4cf78161ad Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Mon, 27 Jul 2026 18:24:37 +0000 Subject: [PATCH 3/4] test: cover both bun -e and bun entry points --- .../test-auto-import-jest-globals.test.js | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/test/js/bun/test/test-auto-import-jest-globals.test.js b/test/js/bun/test/test-auto-import-jest-globals.test.js index b68574ea2173..c52605cb2830 100644 --- a/test/js/bun/test/test-auto-import-jest-globals.test.js +++ b/test/js/bun/test/test-auto-import-jest-globals.test.js @@ -1,4 +1,4 @@ -import { bunEnv, bunExe } from "harness"; +import { bunEnv, bunExe, tempDir } from "harness"; test("Jest auto imports", () => { expect(true).toBe(true); @@ -15,16 +15,36 @@ test("Jest auto imports", () => { // Injection is a `bun test`-mode parser transform (#17734 made it apply to every // file loaded by the test runner, not just the entrypoint). The only remaining // scoping guarantee is that ordinary `bun ` / `bun -e` runs do NOT see it. -test("Jest globals are not injected outside of `bun test`", async () => { +describe("Jest globals are not injected outside of `bun test`", () => { const names = ["describe", "it", "test", "expect", "beforeAll", "beforeEach", "afterAll", "afterEach"]; - await using proc = Bun.spawn({ - cmd: [bunExe(), "-e", `process.stdout.write(JSON.stringify({${names.map(n => `${n}: typeof ${n}`).join(", ")}}))`], - env: bunEnv, - stdout: "pipe", - stderr: "pipe", + const source = `process.stdout.write(JSON.stringify({${names.map(n => `${n}: typeof ${n}`).join(", ")}}))`; + const expected = Object.fromEntries(names.map(n => [n, "undefined"])); + + test.concurrent("bun -e", async () => { + await using proc = Bun.spawn({ + cmd: [bunExe(), "-e", source], + env: bunEnv, + stdout: "pipe", + stderr: "pipe", + }); + const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + expect(stderr).toBe(""); + expect(JSON.parse(stdout)).toEqual(expected); + expect(exitCode).toBe(0); + }); + + test.concurrent("bun ", async () => { + using dir = tempDir("jest-globals-not-injected", { "entry.js": source }); + await using proc = Bun.spawn({ + cmd: [bunExe(), "entry.js"], + env: bunEnv, + cwd: String(dir), + stdout: "pipe", + stderr: "pipe", + }); + const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + expect(stderr).toBe(""); + expect(JSON.parse(stdout)).toEqual(expected); + expect(exitCode).toBe(0); }); - const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); - expect(stderr).toBe(""); - expect(JSON.parse(stdout)).toEqual(Object.fromEntries(names.map(n => [n, "undefined"]))); - expect(exitCode).toBe(0); }); From 521bdc4da92ed1aa837fd6c134925281fcbfe365 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Mon, 27 Jul 2026 19:03:48 +0000 Subject: [PATCH 4/4] ci: retrigger