Skip to content

Commit

Permalink
Merge pull request #216 from wanglam/master
Browse files Browse the repository at this point in the history
Support jsx-runtime for jest babel transform
  • Loading branch information
patricklafrance authored Nov 30, 2020
2 parents 3c535d9 + a863dae commit 2479b9e
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/craco/lib/features/jest/create-jest-babel-transform.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
const babelJest = require("babel-jest");

const { isArray } = require("../../utils");
/**
* To check if support jsx-runtime
* Copy from https://github.com/facebook/create-react-app/blob/2b1161b34641bb4d2f269661cd636bbcd4888406/packages/react-scripts/config/jest/babelTransform.js#L12
*/
const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === "true") {
return false;
}

try {
require.resolve("react/jsx-runtime");
return true;
} catch (e) {
return false;
}
})();

function createJestBabelTransform(cracoConfig) {
const craBabelTransformer = {
presets: ["babel-preset-react-app"],
presets: [
[
"babel-preset-react-app",
{
runtime: hasJsxRuntime ? "automatic" : "classic"
}
]
],
babelrc: false,
configFile: false
};
Expand Down

0 comments on commit 2479b9e

Please sign in to comment.