Skip to content

Commit 31e3ffe

Browse files
mostafahJohnNilsson
authored andcommitted
Add "node" to Jest's moduleFileExtensions (#2738)
Jest's default value for this option is ["js", "json", "jsx", "node"]. CRA's current value is ["web.js", "js", "json", "web.jsx", "jsx"], which is missing one of default ones: "node". This change fixes that. This "node" extension is used in packages that use native code.
1 parent 4b856a7 commit 31e3ffe

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

packages/react-scripts/scripts/utils/createJestConfig.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ module.exports = (resolve, rootDir) => {
2727
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
2828
setupFiles: [resolve('config/polyfills.js')],
2929
setupTestFrameworkScriptFile: setupTestsFile,
30-
moduleFileExtensions: [
31-
'web.ts',
32-
'ts',
33-
'web.tsx',
34-
'tsx',
35-
'web.js',
36-
'js',
37-
'web.jsx',
38-
'jsx',
39-
'json',
40-
],
4130
testMatch: [
4231
'<rootDir>/src/**/__tests__/**/*.ts?(x)',
4332
'<rootDir>/src/**/?(*.)(spec|test).ts?(x)',
@@ -47,14 +36,26 @@ module.exports = (resolve, rootDir) => {
4736
transform: {
4837
'^.+\\.css$': resolve('config/jest/cssTransform.js'),
4938
'^.+\\.tsx?$': resolve('config/jest/typescriptTransform.js'),
50-
'^(?!.*\\.(css|json)$)': resolve('config/jest/fileTransform.js'),
39+
'^(?!.*\\.(js|jsx|css|json)$)': resolve('config/jest/fileTransform.js'),
5140
},
5241
transformIgnorePatterns: [
5342
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$',
5443
],
5544
moduleNameMapper: {
5645
'^react-native$': 'react-native-web',
5746
},
47+
moduleFileExtensions: [
48+
'web.ts',
49+
'ts',
50+
'web.tsx',
51+
'tsx',
52+
'web.js',
53+
'js',
54+
'web.jsx',
55+
'jsx',
56+
'json',
57+
'node'
58+
],
5859
globals: {
5960
'ts-jest': {
6061
tsConfigFile: paths.appTsTestConfig,

0 commit comments

Comments
 (0)