Register Babel in Jest setup to load transformer (#39251)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39251

As `react-native/babel-preset` is extended to include parts of codegen (written in Flow) via `react-native/babel-plugin-codegen`, we need to register Babel (with a Node JS config) in order to load the `react-native/babel-transformer` that Jest needs to transform RN code when running from source.

(This is *only* relevant to running from source, ie internally at Meta or when developing on a clone of the OSS repo)

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D48871440

fbshipit-source-id: 2f206b2380d67007e37782f211a6e831b35291f8
This commit is contained in:
Rob Hogan 2023-09-01 04:43:41 -07:00 committed by Facebook GitHub Bot
parent aa2a0c1115
commit 5c513cb2f8

View File

@ -32,6 +32,8 @@ const nodeFiles = /[\\/]metro(?:-[^/]*)[\\/]/;
// hook. This is used below to configure babelTransformSync under Jest.
const {only: _, ...nodeBabelOptions} = metroBabelRegister.config([]);
// Register Babel to allow the transformer itself to be loaded from source.
require('../scripts/build/babel-register').registerForMonorepo();
const transformer = require('@react-native/metro-babel-transformer');
module.exports = {