Skip to content

Allow users to override roots in Jest config #12808

@beeryt

Description

@beeryt

Is your proposal related to a problem?

#7480 set jest config key roots to be <rootDir>/src. However this locks users into putting all jest-related files under the src directory.

Jest is unable to locate my tests if they are not located in the <rootDir>/src folder.
Given the following override to testMatch files in <rootDir>/features will never match.

"jest": {
  "testMatch": [
    "<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}",
    "<rootDir>/features/**/*.steps.{js,ts}"
  ]
}

Describe the solution you'd like

A) react-scripts/scripts/utils/createJestConfig.js could add roots to supportedKeys to allow users to override default.

This would be the simplest change and give users the most control. Exposing the remaining *PathIgnorePatterns config keys would give users complete control to avoid parsing node_modules.

Describe alternatives you've considered

B) createJestConfig.js could support non-standard key, additionalRoots, which gets appended to `config['roots']

This would help avoid users accidentally dropping <rootDir>/src from config['roots'], but may need additional documentation.

C) createJestConfig.js could examine overrides['testMatch'] to determine additional folders required for config['roots']

This would involve extra logic in createJestConfig.js and is probably not desirable

Additional context

#7480 was introduced with #7458 because node_modules was being parsed and reducing performance

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions