From 5c513cb2f831bb0f705973f844b2c4d6b23106d8 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Fri, 1 Sep 2023 04:43:41 -0700 Subject: [PATCH] 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 --- jest/preprocessor.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jest/preprocessor.js b/jest/preprocessor.js index e42797a5977..ae9f6dd90b9 100644 --- a/jest/preprocessor.js +++ b/jest/preprocessor.js @@ -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 = {