From 01eaa6db97866ee0c267960c32ffc8cada949207 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Fri, 25 Jul 2025 13:52:59 -0700 Subject: [PATCH] Mock prettier import through actual require to prepare for prettier v3 (#52843) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52843 Changelog: [Internal] Reviewed By: pieterv Differential Revision: D78993226 fbshipit-source-id: 03f43c61fe9e6edaf38f895daf4f0c146df931b8 --- packages/react-native/jest/setup.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/react-native/jest/setup.js b/packages/react-native/jest/setup.js index 9af8d76313d..9cdfe0f7a98 100644 --- a/packages/react-native/jest/setup.js +++ b/packages/react-native/jest/setup.js @@ -70,6 +70,17 @@ Object.defineProperties(global, { }, }); +/** + * Prettier v3 uses import (cjs/mjs) file formats that jest-runtime does not + * support. To work around this we need to bypass the jest module system by + * using the orginal node `require` function. + */ +jest.mock('prettier', () => { + // $FlowExpectedError[underconstrained-implicit-instantiation] + const module = jest.requireActual('module'); + return module.prototype.require(require.resolve('prettier')); +}); + // $FlowFixMe[incompatible-call] - `./mocks/AppState` is incomplete. mock('m#../Libraries/AppState/AppState', 'm#./mocks/AppState'); mock('m#../Libraries/BatchedBridge/NativeModules', 'm#./mocks/NativeModules');