mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Fix Jest globals not being available in non-entrypoint files (#17734)
This commit is contained in:
@@ -474,7 +474,7 @@ pub const RuntimeTranspilerStore = struct {
|
||||
.virtual_source = null,
|
||||
.dont_bundle_twice = true,
|
||||
.allow_commonjs = true,
|
||||
.inject_jest_globals = transpiler.options.rewrite_jest_for_tests and is_main,
|
||||
.inject_jest_globals = transpiler.options.rewrite_jest_for_tests,
|
||||
.set_breakpoint_on_first_line = vm.debugger != null and
|
||||
vm.debugger.?.set_breakpoint_on_first_line and
|
||||
is_main and
|
||||
@@ -1623,7 +1623,7 @@ pub const ModuleLoader = struct {
|
||||
.virtual_source = virtual_source,
|
||||
.dont_bundle_twice = true,
|
||||
.allow_commonjs = true,
|
||||
.inject_jest_globals = jsc_vm.transpiler.options.rewrite_jest_for_tests and is_main,
|
||||
.inject_jest_globals = jsc_vm.transpiler.options.rewrite_jest_for_tests,
|
||||
.keep_json_and_toml_as_one_statement = true,
|
||||
.allow_bytecode_cache = true,
|
||||
.set_breakpoint_on_first_line = is_main and
|
||||
|
||||
25
test/regression/issue/12034/12034.fixture.ts
Normal file
25
test/regression/issue/12034/12034.fixture.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// A fixture that tests that Jest globals are injected into the global scope
|
||||
// even when the file is NOT the entrypoint of the test.
|
||||
|
||||
test.each([
|
||||
["expect", expect],
|
||||
["test", test],
|
||||
["describe", describe],
|
||||
["it", it],
|
||||
["beforeEach", beforeEach],
|
||||
["afterEach", afterEach],
|
||||
["beforeAll", beforeAll],
|
||||
["afterAll", afterAll],
|
||||
["jest", jest],
|
||||
])("that %s is defined", (_, global) => {
|
||||
expect(global).toBeDefined();
|
||||
});
|
||||
|
||||
expect.extend({
|
||||
toBeOne(actual) {
|
||||
return {
|
||||
pass: actual === 1,
|
||||
message: () => `expected ${actual} to be 1`,
|
||||
};
|
||||
},
|
||||
});
|
||||
8
test/regression/issue/12034/12034.test.js
Normal file
8
test/regression/issue/12034/12034.test.js
Normal file
@@ -0,0 +1,8 @@
|
||||
// This fixture tests that Jest global variables are injected into the global scope
|
||||
// even when the file is NOT the entrypoint of the test.
|
||||
import "./12034.fixture";
|
||||
|
||||
test("that an imported file can use Jest globals", () => {
|
||||
expect(1).toBeOne();
|
||||
expect(2).not.toBeOne();
|
||||
});
|
||||
Reference in New Issue
Block a user