From 074ad478c951de528c4c57370d2a0082cca6687e Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 6 Oct 2017 15:14:39 +0200 Subject: [PATCH] Try to set parent to actual parent module --- packages/jest-runtime/src/index.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 04c319cfd1fc..68fd641c9b1a 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -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; @@ -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; @@ -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,