-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Fix Jest crashing on projects with large node_modules folders #2395
Fix Jest crashing on projects with large node_modules folders #2395
Conversation
Wow that was quick, thanks a lot! |
'<rootDir>/src/**/__tests__/**/*.js?(x)', | ||
'<rootDir>/src/**/?(*.)(spec|test).js?(x)', | ||
modulePathIgnorePatterns: [ | ||
'<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to add dist
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more about it in a perfect world everything in .gitignore should go here... coverage
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added dist as it's a common folder.
.gitignore
really focuses on something different even if 99% of the time it's the same.
Its better to accidentally watch a folder that doesn't need to be watched than to accidentally not-watch a folder that should be watched.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that makes sense thanks again!
1983cda
to
53e4cd3
Compare
'<rootDir>/src/**/__tests__/**/*.js?(x)', | ||
'<rootDir>/src/**/?(*.)(spec|test).js?(x)', | ||
modulePathIgnorePatterns: [ | ||
'<rootDir>[/\\\\](build|dist|docs|node_modules|scripts)[/\\\\]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! What about coverage
that is created when npm run coverage
is called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess nobody is watching and running coverage at the same time, ignore this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No harm adding it. But we can't cover everything. The main purpose for this really is to not watch node_modules as its too large and crashes Jest.
53e4cd3
to
83543a6
Compare
83543a6
to
14e21b2
Compare
For future reference. PR #1614 added Once the underlining issue is solved at jestjs/jest#1767 we can revert back to The Regex at the time of this PR was testMatches: [
'<rootDir>/src/**/__tests__/**/*.js?(x)',
'<rootDir>/src/**/?(*.)(spec|test).js?(x)',
] |
@cpojer Is |
No plans to remove it. |
Note that when people try to debug something by changing files inside of node_modules, Jest will not re-run tests with this change applied. |
Fair enough, but better than instacrashing 😄 |
// Once this is fixes we can change from `modulePathIgnorePatterns` to `testMatches`. | ||
// See facebook/jest/issues/1767 & facebookincubator/create-react-app/pull/2395 | ||
modulePathIgnorePatterns: [ | ||
'<rootDir>[/\\\\](build|dist|docs|node_modules|coverage|scripts|bower_components)[/\\\\]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this still includes any arbitrary folders other than these? We specifically fixed it in 1.0 and I don't want to regress on it. Can we use a negative lookahead to ignore everything but src
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should work, but every time I regex I am worried I'll miss something.
<rootDir>\/(?!src).*\/.*
I did a couple tests locally and it worked fine.
14e21b2
to
09b29e2
Compare
09b29e2
to
5bc5076
Compare
// Which causes crashes on large projects on MacOS. | ||
// Once this is fixes we can change from `modulePathIgnorePatterns` to `testMatches`. | ||
// See facebook/jest/issues/1767 & facebookincubator/create-react-app/pull/2395 | ||
modulePathIgnorePatterns: ['<rootDir>\/(?!src).*\/.*'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested, works for me. Thanks again
@thisconnect does installing It's a little inconvenient to switch away from
Cloning your repo on my macOS system does reproduce for me, but only after I uninstall Maybe we could recommend this in CRA, or Jest could and then handle Does Windows have this problem? |
The watchman situation is really unfortunate. We should either make it a hard dependency on macOS or make things work without it. Windows doesn’t have this problem (and watchman doesn’t work there anyway). |
@Timer We could use some of your digging in skills in figuring out what's the best place to fix it. |
I have never installed watchman nor now anything about it. However watching Is watching + edit A compromise could be, if possible, to detect if watchman is installed. It could be mentioned in the readme as feature "Hey if you install watchman you can live edit and debug stuff in node_modules" |
Yea, I think it would be nice if we could detect watchman. When it exists we opt for more aggressive watching (including node_modules). When it doesn't (and system doesn't support watchman) then we don't try it. I'm also curious why we can't just teach Jest to use chokidar which is what Webpack is using. |
|
IMO, we need to teach Jest how to use
Unfortunately I think this wouldn't be good for cross-machine ejected apps, don't we serialize the Jest config into |
The fun part is you don't need to know anything about it, all you need to do is AFAIK it handles the performance implications of such a large amount of files. I don't even know that much about it, other than it's Facebook's file watcher. 🤷♀️ |
We could do it in the test script itself. |
I guess I'm cool with making watchman a required dependency on OS X for watch mode. |
We could, I'm a little tied up for the rest of today but I can take a look at this tomorrow.
Have the weird issues with watchman been sorted out on macOS? I know we had a whole section in our docs dedicated to troubleshooting it. @ro-savage also seems very willing to help, maybe he could provide a recommendation as well. |
I think that is the issue: it crashes without watchman. There was another issue about it hanging with watchman but I think (am I wrong? not sure) it was sorted with one of watchman’s updates. |
So it seems you all definitely want to watch node_modules ? |
If we have watchman then yes, I think it's fine to watch them. And it seems like Node crawler works fine outside of macOS so we only need to not watch it only on macOS without watchman. At this point we might as well require macOS users to install watchman as it seems simpler? |
I think it depends a lot of we can install watchman as part of the normal npm install. If we can, then its not really much of an issue. If the user needs to Long term, the issue itself exists in the way node watches files and a fix needs to happen in node. I know in nodejs/node-v0.x-archive/issues/5463 node blamed OSX but seeing as watchman works fine on OSX surely node could work fine as well? |
Can you remind me why we can't switch Jest Node crawler to use Chokidar (which works fine on macOS)? |
In terms of history, I believe |
See facebook/react-native#628 and facebook/react-native#5 (comment) for some historical context -- featuring a conversation between @gaearon and @amasad. 😅 I'm not sure if there's a real reason to not switch now. |
Watchman still makes sense as first solution. But we should fall back to |
Eh, I still don't understand what's going on 😞 We know Webpack uses Chokidar which uses fsevents on macOS. Nevertheless there is no problem with Webpack. Jest, on the other hand, produces an error message inside of fsevents. However I can't find a single mention of fsevents or even fs.watch in its Node crawler. Can somebody explain:
|
OK, I understand what happens now. I shouldn't look at "crawler", I should look at "watcher". Which comes from sane which uses fs.watch. Which presumably uses |
@gaearon fsevents means two things here it's the OS X native filesystem events and the node module. Watchman, Node, and the fsevents npm module use FSEvents for watching. I thought this was fixed in recent node releases but maybe it's not: node would overload FSEvents by starting much more watches than it needs. Watchman solves this by multiplexing on the same watch channel. I'm not sure how chokidar solves it. IMO making watchman a hard dependency is better than taking on fsevents as a dependency. IIRC watchman is now installable via npm right? But also open to suggestions on how to make sane better. |
Started an FSEventsWatcher branch on sane. Still needs some work, I'll try to finish it soon but someone else want's to jump in feel free to amasad/sane#97 |
We'll go with @amasad's approach instead. It will make it to Jest within a few weeks. |
Fixes #2393
This PR fixes an ongoing issue with large
node_modules
folders andcreate-react-app
tests.The underlining issue is with Jest and how it watches files, and the current method that is used for
testMatches
means that files innode_modules
are watched and crashes jest.@thisconnect created issue #2393 that shows how to reproduce the error and included an example repo.
This PR uses
modulePathIgnorePatterns
to decide what to watch/not-watch instead oftestMatches
and correctly ignoresnode_modules
. As seen in Jest issue jestjs/jest/issues/1767