diff --git a/CHANGELOG.md b/CHANGELOG.md index 59327bcc66b9..350428d133b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixes - `[jest-runtime]` `require.main` is no longer `undefined` when using `jest.resetModules` ([#10626](https://github.com/facebook/jest/pull/10626)) +- `[jest-runtime]` Do not inject `global` variable into module wrapper ([#10644](https://github.com/facebook/jest/pull/10644)) - `[@jest/types]` Add missing values for `timers` ([#10632](https://github.com/facebook/jest/pull/10632)) ### Chore & Maintenance diff --git a/e2e/__tests__/global-mutation.test.ts b/e2e/__tests__/global-mutation.test.ts new file mode 100644 index 000000000000..828ee674f347 --- /dev/null +++ b/e2e/__tests__/global-mutation.test.ts @@ -0,0 +1,12 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +const global = 'woo!'; + +test('can redefine global', () => { + expect(global).toBe('woo!'); +}); diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index 3a28550df5e4..f0d1c3686f8c 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -29,7 +29,6 @@ export type ModuleWrapper = ( require: Module['require'], __dirname: string, __filename: Module['filename'], - global: Global.Global, jest?: Jest, ...extraGlobals: Array ) => unknown; diff --git a/packages/jest-runtime/src/__tests__/__snapshots__/runtime_wrap.js.snap b/packages/jest-runtime/src/__tests__/__snapshots__/runtime_wrap.js.snap index fd65bf149b33..31e19b94d748 100644 --- a/packages/jest-runtime/src/__tests__/__snapshots__/runtime_wrap.js.snap +++ b/packages/jest-runtime/src/__tests__/__snapshots__/runtime_wrap.js.snap @@ -1,11 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Runtime wrapCodeInModuleWrapper generates the correct args for the module wrapper 1`] = ` -({"Object.":function(module,exports,require,__dirname,__filename,global,jest){module.exports = "Hello!" +({"Object.":function(module,exports,require,__dirname,__filename,jest){module.exports = "Hello!" }}); `; exports[`Runtime wrapCodeInModuleWrapper injects "extra globals" 1`] = ` -({"Object.":function(module,exports,require,__dirname,__filename,global,jest,Math){module.exports = "Hello!" +({"Object.":function(module,exports,require,__dirname,__filename,jest,Math){module.exports = "Hello!" }}); `; diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index b19b0dbf1cce..5ec58aa77bad 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -366,7 +366,7 @@ class Runtime { invariant(context); if (this._resolver.isCoreModule(modulePath)) { - const core = await this._importCoreModule(modulePath, context); + const core = this._importCoreModule(modulePath, context); this._esmoduleRegistry.set(cacheKey, core); return core; } @@ -1078,7 +1078,6 @@ class Runtime { module.require, // require implementation module.path, // __dirname module.filename, // __filename - this._environment.global, // global object ...lastArgs.filter(notEmpty), ); } catch (error) { @@ -1632,7 +1631,6 @@ class Runtime { 'require', '__dirname', '__filename', - 'global', this._config.injectGlobals ? 'jest' : undefined, ...this._config.extraGlobals, ].filter(notEmpty);