The Jest configuration does not have to be in the package.json, it can be put in an external file.

Create a .jestrc file

Create a .jestrc file and put your configuration inside. The format is still JSON but the ”jest”: { … }” key at the root is omitted.

package.json
1
2
3
4
5
6
7
{
[…],
“jest”: {
"testRegex": "tests/.*\\.(js|jsx)$"
},
[…]
}

becomes

.jestrc
1
2
3
{
"testRegex": "tests/.*\\.(js|jsx)$"
}

Use the —config option when calling jest to use the .jestrc file in lieu of the package.json section

1
$ jest config .jestrc

Enjoy !