Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions test/js/bun/test/jest-doesnt-auto-import.js

This file was deleted.

32 changes: 21 additions & 11 deletions test/js/bun/test/test-auto-import-jest-globals.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { bunEnv, bunExe } from "harness";

test("Jest auto imports", () => {
expect(true).toBe(true);
expect(typeof describe).toBe("function");
Expand All @@ -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 <file>` / `bun -e` runs do NOT see it.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
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(", ")}}))`,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
],
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect(stderr).toBe("");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
expect(JSON.parse(stdout)).toEqual(Object.fromEntries(names.map(n => [n, "undefined"])));
expect(exitCode).toBe(0);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
});
Loading