10
10
'use strict' ;
11
11
12
12
const fs = require ( 'fs' ) ;
13
+ const chalk = require ( 'chalk' ) ;
13
14
const paths = require ( '../../config/paths' ) ;
14
15
15
16
module . exports = ( resolve , rootDir , isEjecting ) => {
@@ -27,7 +28,7 @@ module.exports = (resolve, rootDir, isEjecting) => {
27
28
setupTestFrameworkScriptFile : setupTestsFile ,
28
29
testMatch : [
29
30
'<rootDir>/src/**/__tests__/**/*.js?(x)' ,
30
- '<rootDir>/src/**/?(*.)(spec|test).js?(x)'
31
+ '<rootDir>/src/**/?(*.)(spec|test).js?(x)' ,
31
32
] ,
32
33
testEnvironment : 'node' ,
33
34
testURL : 'http://localhost' ,
@@ -46,5 +47,43 @@ module.exports = (resolve, rootDir, isEjecting) => {
46
47
if ( rootDir ) {
47
48
config . rootDir = rootDir ;
48
49
}
50
+ const overrides = Object . assign ( { } , require ( paths . appPackageJson ) . jest ) ;
51
+ const supportedKeys = [
52
+ 'collectCoverageFrom' ,
53
+ 'coverageReporters' ,
54
+ 'coverageThreshold' ,
55
+ 'snapshotSerializers' ,
56
+ ] ;
57
+ if ( overrides ) {
58
+ supportedKeys . forEach ( key => {
59
+ if ( overrides . hasOwnProperty ( key ) ) {
60
+ config [ key ] = overrides [ key ] ;
61
+ delete overrides [ key ] ;
62
+ }
63
+ } ) ;
64
+ const unsupportedKeys = Object . keys ( overrides ) ;
65
+ if ( unsupportedKeys . length ) {
66
+ console . error (
67
+ chalk . red (
68
+ 'Out of the box, Create React App only supports overriding ' +
69
+ 'these Jest options:\n\n' +
70
+ supportedKeys . map ( key => chalk . bold ( ' \u2022 ' + key ) ) . join ( '\n' ) +
71
+ '.\n\n' +
72
+ 'These options in your package.json Jest configuration ' +
73
+ 'are not currently supported by Create React App:\n\n' +
74
+ unsupportedKeys
75
+ . map ( key => chalk . bold ( ' \u2022 ' + key ) )
76
+ . join ( '\n' ) +
77
+ '\n\nIf you wish to override other Jest options, you need to ' +
78
+ 'eject from the default setup. You can do so by running ' +
79
+ chalk . bold ( 'npm run eject' ) +
80
+ ' but remember that this is a one-way operation. ' +
81
+ 'You may also file an issue with Create React App to discuss ' +
82
+ 'supporting more options out of the box.\n'
83
+ )
84
+ ) ;
85
+ process . exit ( 1 ) ;
86
+ }
87
+ }
49
88
return config ;
50
89
} ;
0 commit comments