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
This commit is contained in:
Sam Zhou
2025-07-25 13:52:59 -07:00
committed by Facebook GitHub Bot
parent 627136ee76
commit 01eaa6db97
+11
View File
@@ -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');