Skip to content

Commit

Permalink
fix: do not inject global var into module wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 18, 2020
1 parent e84a70c commit 494e1de
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions 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!');
});
1 change: 0 additions & 1 deletion packages/jest-environment/src/index.ts
Expand Up @@ -29,7 +29,6 @@ export type ModuleWrapper = (
require: Module['require'],
__dirname: string,
__filename: Module['filename'],
global: Global.Global,
jest?: Jest,
...extraGlobals: Array<Global.Global[keyof Global.Global]>
) => unknown;
Expand Down
4 changes: 1 addition & 3 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1632,7 +1631,6 @@ class Runtime {
'require',
'__dirname',
'__filename',
'global',
this._config.injectGlobals ? 'jest' : undefined,
...this._config.extraGlobals,
].filter(notEmpty);
Expand Down

0 comments on commit 494e1de

Please sign in to comment.