Skip to content

Commit

Permalink
Implement module.parent.id
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 6, 2017
1 parent b91bbd6 commit 7b0e219
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Runtime requireModule', () => {
expect(exports.parent).toEqual({
exports: {},
filename: '',
id: 'mockParent',
id: '',
require: expect.any(Function),
});
}));
Expand Down
12 changes: 4 additions & 8 deletions packages/jest-runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ const getModuleNameMapper = (config: ProjectConfig) => {
return null;
};

const mockParentModule = {
exports: {},
id: 'mockParent',
};

const unmockRegExpCache = new WeakMap();

class Runtime {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7b0e219

Please sign in to comment.