Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement module.parent.id
  • Loading branch information
SimenB committed Oct 6, 2017
commit f9658fd826092db2b9cc84610f9415709873d3ac
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this look up the parent module in jest-runtime and use its require here, instead of creating a new require implementation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I can access the parent module, then that'd be perfect (as that's what module.parent is in node). I didn't find it though. Halp?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we storing this in jest-runtime somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might be, I'll check

lastExecutingModulePath,
options,
),
});
};

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