Skip to content
Prev Previous commit
Next Next commit
Try to set parent to actual parent module
  • Loading branch information
SimenB committed Oct 6, 2017
commit 074ad478c951de528c4c57370d2a0082cca6687e
18 changes: 7 additions & 11 deletions packages/jest-runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class Runtime {
// $FlowFixMe
localModule.exports = require(modulePath);
} else {
this._execModule(localModule, options);
this._execModule(localModule, options, moduleRegistry[from]);
}
}
return moduleRegistry[modulePath].exports;
Expand Down Expand Up @@ -472,7 +472,11 @@ class Runtime {
return to ? this._resolver.resolveModule(from, to) : from;
}

_execModule(localModule: Module, options: ?InternalModuleOptions) {
_execModule(
localModule: Module,
options: ?InternalModuleOptions,
parent?: Module,
) {
// If the environment was disposed, prevent this module from being executed.
if (!this._environment.global) {
return;
Expand All @@ -489,15 +493,7 @@ class Runtime {
localModule.children = [];
localModule.paths = this._resolver.getModulePaths(dirname);
localModule.require = this._createRequireImplementation(filename, options);
localModule.parent = {
exports: {},
filename: lastExecutingModulePath,
id: lastExecutingModulePath,
require: this._createRequireImplementation(
lastExecutingModulePath,
options,
),
};
localModule.parent = parent;

const transformedFile = this._scriptTransformer.transform(
filename,
Expand Down