Skip to content

Commit

Permalink
Pass JSX runtime setting to Babel preset in Jest config (#9865)
Browse files Browse the repository at this point in the history
  • Loading branch information
iansu committed Oct 23, 2020
1 parent f2aef41 commit 2b1161b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/react-scripts/config/jest/babelTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,28 @@

const babelJest = 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;
}
})();

module.exports = babelJest.createTransformer({
presets: [require.resolve('babel-preset-react-app')],
presets: [
[
require.resolve('babel-preset-react-app'),
{
runtime: hasJsxRuntime ? 'automatic' : 'classic',
},
],
],
babelrc: false,
configFile: false,
});

0 comments on commit 2b1161b

Please sign in to comment.