diff --git a/packages/jest-runtime/src/__tests__/runtime_require_module.test.js b/packages/jest-runtime/src/__tests__/runtime_require_module.test.js index d688a0d7e0ad..a8d06ce7f8cc 100644 --- a/packages/jest-runtime/src/__tests__/runtime_require_module.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_require_module.test.js @@ -36,7 +36,7 @@ describe('Runtime requireModule', () => { expect(exports.parent).toEqual({ exports: {}, filename: '', - id: 'mockParent', + id: '', require: expect.any(Function), }); })); diff --git a/packages/jest-runtime/src/index.js b/packages/jest-runtime/src/index.js index 67e1bf8b900c..04c319cfd1fc 100644 --- a/packages/jest-runtime/src/index.js +++ b/packages/jest-runtime/src/index.js @@ -75,11 +75,6 @@ const getModuleNameMapper = (config: ProjectConfig) => { return null; }; -const mockParentModule = { - exports: {}, - id: 'mockParent', -}; - const unmockRegExpCache = new WeakMap(); class Runtime { @@ -492,16 +487,17 @@ class Runtime { const dirname = path.dirname(filename); localModule.children = []; - localModule.parent = mockParentModule; localModule.paths = this._resolver.getModulePaths(dirname); localModule.require = this._createRequireImplementation(filename, options); - localModule.parent = Object.assign({}, localModule.parent, { + localModule.parent = { + exports: {}, filename: lastExecutingModulePath, + id: lastExecutingModulePath, require: this._createRequireImplementation( lastExecutingModulePath, options, ), - }); + }; const transformedFile = this._scriptTransformer.transform( filename,