Add support for Jest option "testMatch"
Created by: mljohns89
Problem
Jest has a configuration option called "testMatch" which CRA doesn't currently allow you to override out of the box.
If I try adding the following to my package.json:
"jest": {
"testMatch": [
"**/*.steps.ts"
]
}
I get the following error when running npm test
:
Out of the box, Create React App only supports overriding these Jest options:
• clearMocks
• collectCoverageFrom
• coveragePathIgnorePatterns
• coverageReporters
• coverageThreshold
• displayName
• extraGlobals
• globalSetup
• globalTeardown
• moduleNameMapper
• resetMocks
• resetModules
• restoreMocks
• snapshotSerializers
• transform
• transformIgnorePatterns
• watchPathIgnorePatterns.
These options in your package.json Jest configuration are not currently supported by Create React App:
• testMatch
If you wish to override other Jest options, you need to eject from the default setup. You can do so by running npm run eject but remember that this is a one-way operation. You may also file an issue with Create React App to discuss supporting more options out of the box.
Proposed Solution
It would be nice if this was supported without having to go through the process of ejecting
Ideally, adding this configuration option would just extend the existing Jest testMatch options:
- Files with .js suffix in __tests__ folders.
- Files with .test.js suffix.
- Files with .spec.js suffix.
And not completely override them.
Additional Info
I am somewhat new to React Development, only been developing with React for about 2 years now; so if there is a decent work-around, I am all ears. I prefer using Typescript, React and CRA added Typescript support and files with the extension test.tsx
are supported out of the box. It would just be nice to have support for this Jest option too though as it seems to be a common Jest option that people will change depending on their preferences in test file naming conventions.