Uh oh!
There was an error while loading. Please reload this page.
Fix Jest crashing on projects with large node_modules folders - #2395
Fix Jest crashing on projects with large node_modules folders#2395ro-savage wants to merge 1 commit into
Conversation
thisconnect
commented
May 28, 2017
Wow that was quick, thanks a lot! |
There was a problem hiding this comment.
Would it be possible to add dist as well?
There was a problem hiding this comment.
Thinking more about it in a perfect world everything in .gitignore should go here... coverage etc.
There was a problem hiding this comment.
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.
1983cda to
53e4cd3CompareThere was a problem hiding this comment.
Thanks! What about coverage that is created when npm run coverage is called
There was a problem hiding this comment.
I guess nobody is watching and running coverage at the same time, ignore this comment
There was a problem hiding this comment.
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
83543a6Compare83543a6 to
14e21b2CompareFor 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)',] |
gaearon
commented
May 28, 2017
@cpojer Is |
cpojer
commented
May 28, 2017
No plans to remove it. |
cpojer
commented
May 28, 2017
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. |
gaearon
commented
May 28, 2017
Fair enough, but better than instacrashing 😄 |
There was a problem hiding this comment.
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.
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
09b29e2Compare09b29e2 to
5bc5076Compare| // 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.
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? |
gaearon
commented
May 29, 2017
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). |
gaearon
commented
May 29, 2017
@Timer We could use some of your digging in skills in figuring out what's the best place to fix it. |
thisconnect
commented
May 29, 2017
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" |
gaearon
commented
May 29, 2017
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. |
|
Timer
commented
May 29, 2017
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 |
Timer
commented
May 29, 2017
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. 🤷♀️ |
gaearon
commented
May 29, 2017
We could do it in the test script itself. |
gaearon
commented
May 29, 2017
I guess I'm cool with making watchman a required dependency on OS X for watch mode. |
Timer
commented
May 29, 2017
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. |
gaearon
commented
May 29, 2017
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. |
thisconnect
commented
May 29, 2017
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? |
gaearon
commented
May 29, 2017
Can you remind me why we can't switch Jest Node crawler to use Chokidar (which works fine on macOS)? |
Timer
commented
May 29, 2017
In terms of history, I believe |
Timer
commented
May 29, 2017
See react/react-native#628 and react/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. |
gaearon
commented
May 30, 2017
Watchman still makes sense as first solution. But we should fall back to |
gaearon
commented
May 30, 2017
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. |
amasad
commented
May 30, 2017
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 |
gaearon
commented
Jun 27, 2017
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_modulesfolders andcreate-react-apptests.The underlining issue is with Jest and how it watches files, and the current method that is used for
testMatchesmeans that files innode_modulesare watched and crashes jest.@thisconnect created issue #2393 that shows how to reproduce the error and included an example repo.
This PR uses
modulePathIgnorePatternsto decide what to watch/not-watch instead oftestMatchesand correctly ignoresnode_modules. As seen in Jest issue jestjs/jest/issues/1767