Skip to content

Commit 01eaa6d

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Mock prettier import through actual require to prepare for prettier v3 (facebook#52843)
Summary: Pull Request resolved: facebook#52843 Changelog: [Internal] Reviewed By: pieterv Differential Revision: D78993226 fbshipit-source-id: 03f43c61fe9e6edaf38f895daf4f0c146df931b8
1 parent 627136e commit 01eaa6d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/react-native/jest/setup.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ Object.defineProperties(global, {
7070
},
7171
});
7272

73+
/**
74+
* Prettier v3 uses import (cjs/mjs) file formats that jest-runtime does not
75+
* support. To work around this we need to bypass the jest module system by
76+
* using the orginal node `require` function.
77+
*/
78+
jest.mock('prettier', () => {
79+
// $FlowExpectedError[underconstrained-implicit-instantiation]
80+
const module = jest.requireActual('module');
81+
return module.prototype.require(require.resolve('prettier'));
82+
});
83+
7384
// $FlowFixMe[incompatible-call] - `./mocks/AppState` is incomplete.
7485
mock('m#../Libraries/AppState/AppState', 'm#./mocks/AppState');
7586
mock('m#../Libraries/BatchedBridge/NativeModules', 'm#./mocks/NativeModules');

0 commit comments

Comments
 (0)