babelTransform.js 759 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // @remove-on-eject-begin
  2. /**
  3. * Copyright (c) 2014-present, Facebook, Inc.
  4. *
  5. * This source code is licensed under the MIT license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. */
  8. // @remove-on-eject-end
  9. 'use strict';
  10. const babelJest = require('babel-jest');
  11. const hasJsxRuntime = (() => {
  12. if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
  13. return false;
  14. }
  15. try {
  16. require.resolve('react/jsx-runtime');
  17. return true;
  18. } catch (e) {
  19. return false;
  20. }
  21. })();
  22. module.exports = babelJest.createTransformer({
  23. presets: [
  24. [
  25. require.resolve('babel-preset-react-app'),
  26. {
  27. runtime: hasJsxRuntime ? 'automatic' : 'classic',
  28. },
  29. ],
  30. ],
  31. babelrc: false,
  32. configFile: false,
  33. });