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
Is your proposal related to a problem?
#7480 set jest config key
rootsto be<rootDir>/src. However this locks users into putting all jest-related files under thesrcdirectory.Jest is unable to locate my tests if they are not located in the
<rootDir>/srcfolder.Given the following override to
testMatchfiles in<rootDir>/featureswill never match.Describe the solution you'd like
A)
react-scripts/scripts/utils/createJestConfig.jscould addrootstosupportedKeysto allow users to override default.This would be the simplest change and give users the most control. Exposing the remaining
*PathIgnorePatternsconfig keys would give users complete control to avoid parsingnode_modules.Describe alternatives you've considered
B)
createJestConfig.jscould support non-standard key,additionalRoots, which gets appended to `config['roots']This would help avoid users accidentally dropping
<rootDir>/srcfromconfig['roots'], but may need additional documentation.C)
createJestConfig.jscould examineoverrides['testMatch']to determine additional folders required forconfig['roots']This would involve extra logic in
createJestConfig.jsand is probably not desirableAdditional context
#7480 was introduced with #7458 because
node_moduleswas being parsed and reducing performance