Skip to content

Commit

Permalink
support react-scripts 5
Browse files Browse the repository at this point in the history
  • Loading branch information
smmoosavi committed Feb 26, 2022
1 parent c8ecc5a commit d68c010
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ you can find more detail in [this file][css-patch]
| 2.1.2 | 0.1.4 |
| 3.0.0 | 0.2.0 |
| 4.0.0 | 0.3.0 |
| 5.0.0 | 5.0.0-0 |

## Thanks

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"monkey-react-scripts": "./bin/monkey-react-scripts.js"
},
"peerDependencies": {
"react-scripts": ">=2.0.0"
"react-scripts": ">=5.0.0"
}
}
28 changes: 16 additions & 12 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const webpackMonkeyPath = path.resolve(appPath, 'webpack.monkey.js');
require('react-scripts/config/jest/babelTransform.js')

if (fs.existsSync(webpackMonkeyPath)) {
console.log(chalk.yellow('WARNING! .babelrc file is enabled!'));
const babelJest = require('babel-jest');
console.log(chalk.yellow('WARNING! .babelrc file is enabled!'));
const babelJest = require('babel-jest').default;

const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
Expand All @@ -32,16 +32,20 @@ if (fs.existsSync(webpackMonkeyPath)) {
}
})();

patchModule('react-scripts/config/jest/babelTransform.js', babelJest.createTransformer({
presets: [
require.resolve('babel-preset-react-app'),
{
runtime: hasJsxRuntime ? 'automatic' : 'classic',
},
],
babelrc: true,
configFile: false,
}));
const babelTransform = babelJest.createTransformer({
presets: [
[
require.resolve('babel-preset-react-app'),
{
runtime: hasJsxRuntime ? 'automatic' : 'classic',
},
],
],
babelrc: true,
configFile: false,
});

patchModule('react-scripts/config/jest/babelTransform.js', babelTransform);
}

require('react-scripts/scripts/test');

0 comments on commit d68c010

Please sign in to comment.