5
5
* This source code is licensed under the MIT license found in the
6
6
* LICENSE file in the root directory of this source tree.
7
7
*/
8
- ' use strict' ;
8
+ " use strict" ;
9
9
10
- const fs = require ( 'fs' ) ;
11
- const chalk = require ( ' chalk' ) ;
12
- const paths = require ( ' ../../config/paths' ) ;
10
+ const fs = require ( "fs" ) ;
11
+ const chalk = require ( " chalk" ) ;
12
+ const paths = require ( " ../../config/paths" ) ;
13
13
14
14
module . exports = ( resolve , rootDir , isEjecting ) => {
15
15
// Use this instead of `paths.testsSetup` to avoid putting
16
16
// an absolute filename into configuration after ejecting.
17
17
const setupTestsFile = fs . existsSync ( paths . testsSetup )
18
- ? ' <rootDir>/src/setupTests.js'
18
+ ? " <rootDir>/src/setupTests.js"
19
19
: undefined ;
20
20
21
21
// TODO: I don't know if it's safe or not to just use / as path separator
22
22
// in Jest configs. We need help from somebody with Windows to determine this.
23
23
const config = {
24
- collectCoverageFrom : [ ' src/**/*.{js,jsx,mjs}' ] ,
25
- setupFiles : [ resolve ( ' config/polyfills.js' ) ] ,
24
+ collectCoverageFrom : [ " src/**/*.{js,jsx,mjs}" ] ,
25
+ setupFiles : [ resolve ( " config/polyfills.js" ) ] ,
26
26
setupTestFrameworkScriptFile : setupTestsFile ,
27
27
testMatch : [
28
- ' <rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}' ,
29
- ' <rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}' ,
28
+ " <rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}" ,
29
+ " <rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
30
30
] ,
31
- testEnvironment : ' node' ,
32
- testURL : ' http://localhost' ,
31
+ testEnvironment : " node" ,
32
+ testURL : " http://localhost" ,
33
33
transform : {
34
- ' ^.+\\.(js|jsx|mjs)$' : isEjecting
35
- ? ' <rootDir>/node_modules/babel-jest'
36
- : resolve ( ' config/jest/babelTransform.js' ) ,
37
- ' ^.+\\.css$' : resolve ( ' config/jest/cssTransform.js' ) ,
38
- ' ^(?!.*\\.(js|jsx|mjs|css|json)$)' : resolve (
39
- ' config/jest/fileTransform.js'
40
- ) ,
34
+ " ^.+\\.(js|jsx|mjs)$" : isEjecting
35
+ ? " <rootDir>/node_modules/babel-jest"
36
+ : resolve ( " config/jest/babelTransform.js" ) ,
37
+ " ^.+\\.css$" : resolve ( " config/jest/cssTransform.js" ) ,
38
+ " ^(?!.*\\.(js|jsx|mjs|css|json)$)" : resolve (
39
+ " config/jest/fileTransform.js"
40
+ )
41
41
} ,
42
- transformIgnorePatterns : [ ' [/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$' ] ,
42
+ transformIgnorePatterns : [ " [/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$" ] ,
43
43
moduleNameMapper : {
44
- ' ^react-native$' : ' react-native-web' ,
44
+ " ^react-native$" : " react-native-web"
45
45
} ,
46
46
moduleFileExtensions : [
47
- ' web.js' ,
48
- ' mjs' ,
49
- 'js' ,
50
- ' json' ,
51
- ' web.jsx' ,
52
- ' jsx' ,
53
- ' node' ,
54
- ] ,
47
+ " web.js" ,
48
+ " mjs" ,
49
+ "js" ,
50
+ " json" ,
51
+ " web.jsx" ,
52
+ " jsx" ,
53
+ " node"
54
+ ]
55
55
} ;
56
56
if ( rootDir ) {
57
57
config . rootDir = rootDir ;
58
58
}
59
59
const overrides = Object . assign ( { } , require ( paths . appPackageJson ) . jest ) ;
60
60
const supportedKeys = [
61
- ' collectCoverageFrom' ,
62
- ' coverageReporters' ,
63
- ' coverageThreshold' ,
64
- ' snapshotSerializers' ,
61
+ " collectCoverageFrom" ,
62
+ " coverageReporters" ,
63
+ " coverageThreshold" ,
64
+ " snapshotSerializers"
65
65
] ;
66
66
if ( overrides ) {
67
67
supportedKeys . forEach ( key => {
@@ -74,21 +74,21 @@ module.exports = (resolve, rootDir, isEjecting) => {
74
74
if ( unsupportedKeys . length ) {
75
75
console . error (
76
76
chalk . red (
77
- ' Out of the box, Create React App only supports overriding ' +
78
- ' these Jest options:\n\n' +
79
- supportedKeys . map ( key => chalk . bold ( ' \u2022 ' + key ) ) . join ( '\n' ) +
80
- ' .\n\n' +
81
- ' These options in your package.json Jest configuration ' +
82
- ' are not currently supported by Create React App:\n\n' +
77
+ " Out of the box, Create React App only supports overriding " +
78
+ " these Jest options:\n\n" +
79
+ supportedKeys . map ( key => chalk . bold ( " \u2022 " + key ) ) . join ( "\n" ) +
80
+ " .\n\n" +
81
+ " These options in your package.json Jest configuration " +
82
+ " are not currently supported by Create React App:\n\n" +
83
83
unsupportedKeys
84
- . map ( key => chalk . bold ( ' \u2022 ' + key ) )
85
- . join ( '\n' ) +
86
- ' \n\nIf you wish to override other Jest options, you need to ' +
87
- ' eject from the default setup. You can do so by running ' +
88
- chalk . bold ( ' npm run eject' ) +
89
- ' but remember that this is a one-way operation. ' +
90
- ' You may also file an issue with Create React App to discuss ' +
91
- ' supporting more options out of the box.\n'
84
+ . map ( key => chalk . bold ( " \u2022 " + key ) )
85
+ . join ( "\n" ) +
86
+ " \n\nIf you wish to override other Jest options, you need to " +
87
+ " eject from the default setup. You can do so by running " +
88
+ chalk . bold ( " npm run eject" ) +
89
+ " but remember that this is a one-way operation. " +
90
+ " You may also file an issue with Create React App to discuss " +
91
+ " supporting more options out of the box.\n"
92
92
)
93
93
) ;
94
94
process . exit ( 1 ) ;
0 commit comments