Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make node core modules work on modulePathIgnorePatterns #122

Closed
wants to merge 5 commits into from
Closed

Make node core modules work on modulePathIgnorePatterns #122

wants to merge 5 commits into from

Conversation

adaschevici
Copy link

...ock #106
This is not the best fix but it solves the problem for node modules.
I would appreciate some feedback on ways to improve it.
Need to write the tests still.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@ovidiuch
Copy link

ovidiuch commented Sep 2, 2014

@adaschevici

  • The title seems to the truncated message of the first commit, can you add a more suggestive title like "Make modulePathIgnorePatterns work for node modules."?
  • You mention you didn't write tests, but did you run existing ones to see if they all pass?

return this._configShouldMockModuleNames[moduleName] = false;
}

Copy link

Choose a reason for hiding this comment

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

You leaked a new line here, remove it with the next commit.

@adaschevici adaschevici changed the title Added a double check for Node modules and extended the check in should m... Make node core modules work on modulePathIgnorePatterns Sep 2, 2014
@adaschevici
Copy link
Author

@skidding the existing tests pass.

@@ -123,7 +123,6 @@ function Loader(config, environment, resourceMap) {
this._reverseDependencyMap = null;
this._shouldAutoMock = true;
this._configShouldMockModuleNames = {};

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we leave little stuff like this as-is so that git blame signal remains useful?

Copy link
Author

Choose a reason for hiding this comment

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

@jeffmo addressed spacing.

@duereg
Copy link

duereg commented Sep 19, 2014

any progress on this?

@martindanielson
Copy link

I included this fix and got this instead:

c:\node_modules\d3\index.js: Cannot read property 'id' of undefined
    at Object.exports.jsdom (c:\node_modules\d3\node_modules\jsdom\lib\jsdom.js:51:33)
    at c:\node_modules\d3\index.js:1:100
    at Object.runContentWithLocalBindings (c:\node_modules\jest-cli\src\lib\utils.js:315:17)

Running on Windows with the following versions:

    "d3": "^3.4.11",
    "jest-cli": "^0.1.17",

Any thoughts on that or someone else with the same issue?

@jeffkole
Copy link

I applied this fix to master (v0.2.1) and still get the same bug, though the fix works just fine against v0.1.18. Are there any updates on this PR and the issue it addresses?

@adaschevici
Copy link
Author

@jeffkole hey....this was forever ago. I need to figure out what I was doing then and how i would fix it now.
Will probably get to it sometime this week.

Cheers.

@jeffkole
Copy link

Thank you

@@ -591,7 +591,7 @@ Loader.prototype._shouldMock = function(currPath, moduleName) {
this._configShouldMockModuleNames[moduleName] = true;
for (var i = 0; i < this._unmockListRegExps.length; i++) {
unmockRegExp = this._unmockListRegExps[i];
if (unmockRegExp.test(modulePath)) {
if (unmockRegExp.test(modulePath) || modulePath === null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this just never mock node built-ins?

Instead, shouldn't this be something like
unmockRegExp.test(modulePath) || (modulePath === null && unmockRegExp.test(moduleName)?

Otherwise I think this will just always mark node built-ins as unmocked, right?

Copy link
Author

Choose a reason for hiding this comment

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

Yes...this makes the core modules no longer be ignored.

@ghost
Copy link

ghost commented Aug 5, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

@danielstern
Copy link

This would be a very good fix, as this is a bug that can be a bit frustrating very early in the implementation process.

@pheuter
Copy link

pheuter commented Oct 12, 2015

+1

@cpojer
Copy link
Member

cpojer commented Oct 14, 2015

@adaschevici are you still interested in providing a proper fix for this issue?

@adaschevici
Copy link
Author

@cpojer looking into it as the code has shifted around quite a bit since I submitted this pull request.

@adaschevici
Copy link
Author

Hi guys,

Not sure but this has evolved over time and as far as I can tell the modulePathIgnorePatterns is no longer used and the initlal problem was fixed, and i believe the new requirements should be something like:

Make the modulePathIgnorePatterns use aliases in the node_modules. (for example in jquery)
eg add 'jquery' to modulePathIgnorePatterns would make jest not automock the lib.
Am I going into the right direction?

@cpojer cpojer closed this Oct 23, 2015
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants