Skip to content

Adding roots to Jest config #7458

Closed
@mucsi96

Description

@mucsi96

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions