In the node application, where I use Jest to check client side code (testEnvironment: "jsdom") and server side code (testEnvironment: "node"), and also to collect code coverage for client and server side.
I am currently using 4 Jest configuration files with a lot of redundant configuration to accomplish this.
customer
{ "bail": true, "verbose": true, "notify": true, "scriptPreprocessor": "./node_modules/babel-jest", "testPathIgnorePatterns": [ "./node_modules", "./coverage", "./dist", "./build" ], "testRegex": "\\.test\\.js" }
customer coverage
{ "bail": true, "verbose": true, "notify": true, "scriptPreprocessor": "./node_modules/babel-jest", "testPathIgnorePatterns": [ "./node_modules", "./coverage", "./dist", "./build" ], "testRegex": "\\.test\\.js", "collectCoverageFrom": ["**/*.js", "!**/node_modules/**"], "collectCoverage": true, "coverageDirectory": "./coverage", "coveragePathIgnorePatterns": [ "./node_modules", "./coverage", "./dist", "./build", "./test" ], "coverageThreshold": { "global": { "branches": 100, "functions": 100, "lines": 100, "statements": 100 } } }
Server
{ "bail": true, "verbose": true, "notify": true, "scriptPreprocessor": "./node_modules/babel-jest", "testPathIgnorePatterns": [ "./node_modules", "./coverage", "./dist", "./build" ], "testRegex": "\\.test\\.js", "testEnvironment": "node" }
server reach
{ "bail": true, "verbose": true, "notify": true, "scriptPreprocessor": "./node_modules/babel-jest", "testPathIgnorePatterns": [ "./node_modules", "./coverage", "./dist", "./build" ], "testRegex": "\\.test\\.js", "testEnvironment": "node", "collectCoverageFrom": ["**/*.js", "!**/node_modules/**"], "collectCoverage": true, "coverageDirectory": "./coverage", "coveragePathIgnorePatterns": [ "./node_modules", "./coverage", "./dist", "./build", "./test" ], "coverageThreshold": { "global": { "branches": 100, "functions": 100, "lines": 100, "statements": 100 } } }
How can I achieve this without repeating my configuration 4 times? I looked at the preset configuration option. Using this, I have to create a separate package for each configuration. Is this the recommended way?