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

Adding roots to Jest config #7458

Closed
mucsi96 opened this issue Aug 1, 2019 · 4 comments · Fixed by #7480
Closed

Adding roots to Jest config #7458

mucsi96 opened this issue Aug 1, 2019 · 4 comments · Fixed by #7480

Comments

@mucsi96
Copy link
Contributor

mucsi96 commented Aug 1, 2019

test.log

Is your proposal related to a problem?

My problem is that Jest test are running slow. I have tried CRA with TypeScript using npx create-react-app my-app --typescript. After that executing npm test on Windows 10 machine took 35 seconds. I started to investigate why it's so slow. After making a CPU profile I saw huge number of calls to graceful-fs readdir function. After adding a console.log there I discovered that the function was called on every directory inside .git and node_modules folders. See attached log.

Describe the solution you'd like

To try to improve the performance I have added roots: ['<rootDir>/src'], to createJestConfig.js. After that there were no readdir calls apart from src folder. With that the test execution time went down to 20 seconds. This is a 43% speed improvement on my machine.

@mucsi96
Copy link
Contributor Author

mucsi96 commented Aug 1, 2019

I also wanted to optimize further. Seeing the following CPU profile:
image

I am wondering why requiring modules all together needs 15 seconds for single component and test. Would be great if someone with more experience on CPU profiling can take a look. Profile attached.

CPU-20190801T141211.zip

@ianschmitz
Copy link
Contributor

You're right - it seems because we've specified rootDir to be the root of the project, based on their docs it will search all the sub directories for tests even though our testMatch doesn't include node_modules.

Good finding! Would you like to create a PR to add roots?

@mucsi96
Copy link
Contributor Author

mucsi96 commented Aug 6, 2019

Great! Sure I am happy to do that!

@mucsi96
Copy link
Contributor Author

mucsi96 commented Aug 6, 2019

PR raised: #7480

@bugzpodder bugzpodder removed this from the 3.2 milestone Aug 6, 2019
@lock lock bot locked and limited conversation to collaborators Aug 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants