-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: do not inject global
variable into module wrapper
#10644
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ export type ModuleWrapper = ( | |
require: Module['require'], | ||
__dirname: string, | ||
__filename: Module['filename'], | ||
global: Global.Global, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. heh, as I wrote in an edit in the OP - it breaks for JSDOM as that does not have this code |
||
jest?: Jest, | ||
...extraGlobals: Array<Global.Global[keyof Global.Global]> | ||
) => unknown; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Runtime wrapCodeInModuleWrapper generates the correct args for the module wrapper 1`] = ` | ||
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){module.exports = "Hello!" | ||
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){module.exports = "Hello!" | ||
}}); | ||
`; | ||
|
||
exports[`Runtime wrapCodeInModuleWrapper injects "extra globals" 1`] = ` | ||
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest,Math){module.exports = "Hello!" | ||
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest,Math){module.exports = "Hello!" | ||
}}); | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -383,7 +383,7 @@ class Runtime { | |
invariant(context); | ||
|
||
if (this._resolver.isCoreModule(modulePath)) { | ||
const core = await this._importCoreModule(modulePath, context); | ||
const core = this._importCoreModule(modulePath, context); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. random fix - we wanna insert the module into the cache ASAP so we don't create multiple. The cache should only have promises anyways, so this was just an oversight (and would have been a type error if the ESM |
||
this._esmoduleRegistry.set(cacheKey, core); | ||
return core; | ||
} | ||
|
@@ -1123,7 +1123,6 @@ class Runtime { | |
module.require, // require implementation | ||
module.path, // __dirname | ||
module.filename, // __filename | ||
this._environment.global, // global object | ||
// @ts-expect-error | ||
...lastArgs.filter(notEmpty), | ||
); | ||
|
@@ -1678,7 +1677,6 @@ class Runtime { | |
'require', | ||
'__dirname', | ||
'__filename', | ||
'global', | ||
this._config.injectGlobals ? 'jest' : undefined, | ||
...this._config.extraGlobals, | ||
].filter(notEmpty); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the need for this makes it a breaking change as environments haven't had to do this before