-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Make CRA use jest.config.js + add babelCRA
- Loading branch information
Showing
6 changed files
with
89 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module.exports = { | ||
roots: ['<rootDir>/src'], | ||
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'], | ||
setupFiles: ['react-app-polyfill/jsdom'], | ||
// Use `setupTests.js` if you use javascript | ||
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'], | ||
testMatch: [ | ||
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}', | ||
'<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}', | ||
], | ||
testEnvironment: 'jsdom', | ||
testRunner: 'jest-circus/runner.js', | ||
transform: { | ||
'^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': 'jest-preview/transforms/babelCRA', | ||
// Update the regex to support css and sass | ||
'^.+\\.(css|scss|sass)$': 'jest-preview/transforms/css', | ||
'^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': | ||
'jest-preview/transforms/fileCRA', | ||
}, | ||
transformIgnorePatterns: [ | ||
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$', | ||
// Remove to support CSS Modules | ||
// '^.+\\.module\\.(css|sass|scss)$', | ||
], | ||
modulePaths: [], | ||
moduleNameMapper: { | ||
'^react-native$': 'react-native-web', | ||
// Remove to support CSS Modules | ||
// '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy', | ||
}, | ||
moduleFileExtensions: [ | ||
'web.js', | ||
'js', | ||
'web.ts', | ||
'ts', | ||
'web.tsx', | ||
'tsx', | ||
'json', | ||
'web.jsx', | ||
'jsx', | ||
'node', | ||
], | ||
watchPlugins: [ | ||
'jest-watch-typeahead/filename', | ||
'jest-watch-typeahead/testname', | ||
], | ||
resetMocks: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.textOrange { | ||
color: orange; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
const babelJest = require('babel-jest').default || require('babel-jest'); | ||
|
||
const hasJsxRuntime = (() => { | ||
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') { | ||
return false; | ||
} | ||
|
||
try { | ||
require.resolve('react/jsx-runtime'); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
})(); | ||
|
||
export default babelJest.createTransformer({ | ||
presets: [ | ||
[ | ||
require.resolve('babel-preset-react-app', { | ||
// Find `babel-preset-react-app` in user's node_modules | ||
paths: [process.cwd()], | ||
}), | ||
{ | ||
runtime: hasJsxRuntime ? 'automatic' : 'classic', | ||
}, | ||
], | ||
], | ||
babelrc: false, | ||
configFile: false, | ||
}); |