Skip to content

Commit 4fdad9e

Browse files
rubennortefacebook-github-bot
authored andcommitted
Use FB-specific renderers when running tests in Meta infra (#36877)
Summary: Pull Request resolved: #36877 This diffs allows having Meta-specific tests and modules that are only used when running tests in Meta's infra. Meta-specific modules aren't synced to Github, so the OSS versions will be used when running tests on Github. This is needed because we recently some files from React to React Native, including a test that now uses the `ReactFabric` module to test the behavior of public instances in React Native. This module is always using the OSS version of the renderer, but at Meta we have a custom version that's being ignored in tests. Changelog: [internal] Reviewed By: cortinico Differential Revision: D44874631 fbshipit-source-id: e3112041f134240601495a28ba643bce45d802fb
1 parent d49f1eb commit 4fdad9e

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

jest.config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
'use strict';
1111

12+
const {defaults} = require('jest-config');
13+
1214
module.exports = {
1315
transform: {
1416
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$':
@@ -24,7 +26,8 @@ module.exports = {
2426
escapeString: true,
2527
printBasicPrototype: true,
2628
},
27-
testRegex: '/__tests__/.*-test\\.js$',
29+
// This allows running Meta-internal tests with the `-test.fb.js` suffix.
30+
testRegex: '/__tests__/.*-test(\\.fb)?\\.js$',
2831
testPathIgnorePatterns: [
2932
'/node_modules/',
3033
'<rootDir>/packages/react-native/template',
@@ -36,6 +39,13 @@ module.exports = {
3639
defaultPlatform: 'ios',
3740
platforms: ['ios', 'android'],
3841
},
42+
moduleNameMapper: {
43+
// This module is internal to Meta and used by their custom React renderer.
44+
// In tests, we can just use a mock.
45+
'^ReactNativeInternalFeatureFlags$':
46+
'<rootDir>/packages/react-native/jest/ReactNativeInternalFeatureFlagsMock.js',
47+
},
48+
moduleFileExtensions: ['fb.js'].concat(defaults.moduleFileExtensions),
3949
unmockedModulePathPatterns: [
4050
'node_modules/react/',
4151
'packages/react-native/Libraries/Renderer',
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow strict
9+
*/
10+
11+
'use strict';
12+
13+
module.exports = {};

packages/react-native/jest/setup.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,11 @@ jest
374374
__esModule: true,
375375
default: Component,
376376
};
377+
})
378+
// In tests, we can use the default version instead of the one using
379+
// dependency injection.
380+
.mock('../Libraries/ReactNative/RendererProxy', () => {
381+
return jest.requireActual(
382+
'../Libraries/ReactNative/RendererImplementation',
383+
);
377384
});

0 commit comments

Comments
 (0)