You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We use Jest with an un-ejected CRA 2.0 configuration and have noticed extremely slow test speeds when component dependencies are not manually mocked with jest.mock using a factory method.
We added manual mocks with factory methods into a single domain of our code and saw drastic speed improvements. Attempts to use __mock__ directories made no impact.
Below are the results for only that test domain
Before (unmocked):
Test Suites: 74 passed, 74 total
Tests: 183 passed, 183 total
Snapshots: 0 total
Time: 105.903s
Ran all test suites matching /Notifications/i.
✨ Done in 107.97s.
After (mocked with factory methods):
Test Suites: 74 passed, 74 total
Tests: 183 passed, 183 total
Snapshots: 0 total
Time: 14.547s
Ran all test suites matching /Notifications/i.
✨ Done in 17.18s.
Our current hypothesis is this is due to slow module resolution as tests for components with deeper dependency trees see a more drastic improvement when mocked with a factory method, whereas components with shallower dependencies see only marginal improvements.
To Reproduce
Create a component that uses several subcomponents (we're using material-ui, but we've seen similar results without libraries)
While I would expect some overhead for module resolution. I would not expect such a drastic difference in speeds. If this is expected is it documented somewhere?
Link to repl or repo (highly encouraged)
I've tried to reproduce this in repl.it with no success. Unfortunately the project I'm experiencing this on is private.
I will try to create a new CRA 2.0 project and see if I can reproduce and publish here when I get a chance.
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue 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.
🐛 Bug Report
We use Jest with an un-ejected CRA 2.0 configuration and have noticed extremely slow test speeds when component dependencies are not manually mocked with jest.mock using a factory method.
We added manual mocks with factory methods into a single domain of our code and saw drastic speed improvements. Attempts to use __mock__ directories made no impact.
Below are the results for only that test domain
Before (unmocked):
After (mocked with factory methods):
Our current hypothesis is this is due to slow module resolution as tests for components with deeper dependency trees see a more drastic improvement when mocked with a factory method, whereas components with shallower dependencies see only marginal improvements.
To Reproduce
Example:
Expected behavior
While I would expect some overhead for module resolution. I would not expect such a drastic difference in speeds. If this is expected is it documented somewhere?
Link to repl or repo (highly encouraged)
I've tried to reproduce this in repl.it with no success. Unfortunately the project I'm experiencing this on is private.
I will try to create a new CRA 2.0 project and see if I can reproduce and publish here when I get a chance.
Run
npx envinfo --preset jest
Paste the results here:
The text was updated successfully, but these errors were encountered: