Skip to content

Commit

Permalink
Try to set parent to actual parent module
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 6, 2017
1 parent f9658fd commit 074ad47
Showing 1 changed file with 7 additions and 11 deletions.
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

0 comments on commit 074ad47

Please sign in to comment.