From 08a520cf24c066c0adb77da37e34e85dfba1ea03 Mon Sep 17 00:00:00 2001 From: Ian Sutherland Date: Thu, 22 Oct 2020 22:21:02 -0600 Subject: [PATCH] Pass JSX runtime setting to Babel preset in Jest config (#9865) --- .../config/jest/babelTransform.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/config/jest/babelTransform.js b/packages/react-scripts/config/jest/babelTransform.js index 7feed94c59a..c3848181f1b 100644 --- a/packages/react-scripts/config/jest/babelTransform.js +++ b/packages/react-scripts/config/jest/babelTransform.js @@ -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, });