Skip to content

Commit 765d153

Browse files
rubennortemeta-codesync[bot]
authored andcommitted
Complete remaining deep import migration (#58673)
Summary: Pull Request resolved: #58673 Migrate remaining React Native consumer deep imports to supported root and secondary entrypoints. Keep Jest preset package-internal type imports on OSS-exported implementation paths while preserving runtime mock behavior. Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D121588775 fbshipit-source-id: 6f75784647a75b95e8e5e3e706f6299ad97eb146
1 parent f156ef2 commit 765d153

11 files changed

Lines changed: 63 additions & 18 deletions

‎packages/jest-preset/jest/RefreshControlMock.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010

1111
'use strict';
1212

13-
import type {HostComponent} from 'react-native/src/private/types/HostComponent';
13+
import type {HostComponent} from 'react-native';
14+
import typeof * as TReactNative from 'react-native';
1415

1516
import * as React from 'react';
16-
import requireNativeComponent from 'react-native/Libraries/ReactNative/requireNativeComponent';
17+
18+
const {requireNativeComponent} =
19+
jest.requireActual<TReactNative>('react-native');
1720

1821
const RCTRefreshControl: HostComponent<{}> = requireNativeComponent<{}>(
1922
'RCTRefreshControl',

‎packages/jest-preset/jest/__tests__/setup-test.js‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
* @format
99
*/
1010

11-
import NativeExceptionsManager from 'react-native/Libraries/Core/NativeExceptionsManager';
11+
const NativeExceptionsManager = jest.requireMock(
12+
'react-native/Libraries/Core/NativeExceptionsManager',
13+
).default;
1214

1315
test('NativeAnimatedHelper is a mock', () => {
1416
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation(() => {});
@@ -40,3 +42,15 @@ test('NativeExceptionsManager is a mock', () => {
4042
true,
4143
);
4244
});
45+
46+
test('native component mocks work with a partial react-native mock', () => {
47+
jest.isolateModules(() => {
48+
jest.doMock('react-native', () => ({}));
49+
50+
expect(() => {
51+
jest.requireActual<unknown>('../RefreshControlMock');
52+
jest.requireActual<unknown>('../mocks/RefreshControl');
53+
jest.requireActual<unknown>('../mocks/ScrollView');
54+
}).not.toThrow();
55+
});
56+
});

‎packages/jest-preset/jest/mockNativeComponent.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow strict
7+
* @flow strict-local
88
* @format
99
*/
1010

11-
import type {HostInstance} from 'react-native/src/private/types/HostInstance';
11+
import type {HostInstance} from 'react-native';
1212

1313
import * as React from 'react';
1414
import {createElement} from 'react';

‎packages/jest-preset/jest/mocks/NativeAnimatedHelper.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @format
99
*/
1010

11+
// $FlowFixMe[cannot-resolve-module]
1112
import typeof TNativeAnimatedHelper from 'react-native/src/private/animated/NativeAnimatedHelper';
1213

1314
const NativeAnimatedHelper = jest.requireActual<{

‎packages/jest-preset/jest/mocks/NativeComponentRegistry.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow strict
7+
* @flow strict-local
88
* @format
99
*/
1010

‎packages/jest-preset/jest/mocks/RefreshControl.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
* @format
99
*/
1010

11-
import type {RefreshControlProps} from 'react-native';
12-
import type {HostComponent} from 'react-native/src/private/types/HostComponent';
11+
import type {HostComponent, RefreshControlProps} from 'react-native';
12+
import typeof * as TReactNative from 'react-native';
1313

1414
import * as React from 'react';
15-
import requireNativeComponent from 'react-native/Libraries/ReactNative/requireNativeComponent';
15+
16+
const {requireNativeComponent} =
17+
jest.requireActual<TReactNative>('react-native');
1618

1719
const RCTRefreshControl: HostComponent<{}> = requireNativeComponent<{}>(
1820
'RCTRefreshControl',

‎packages/jest-preset/jest/mocks/RendererProxy.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
// In tests, we can use the default version without dependency injection.
1212

13+
// $FlowFixMe[cannot-resolve-module]
1314
import typeof * as TRendererImplementation from 'react-native/Libraries/ReactNative/RendererImplementation';
1415

1516
const {

‎packages/jest-preset/jest/mocks/ScrollView.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@
1010

1111
import typeof * as TmockComponent from '../mockComponent';
1212
import typeof * as TMockNativeMethods from '../MockNativeMethods';
13+
import type {ScrollViewProps} from 'react-native';
14+
import typeof * as TReactNative from 'react-native';
1315
import typeof {ScrollView as TScrollView} from 'react-native';
14-
import type {ScrollViewNativeProps} from 'react-native/Libraries/Components/ScrollView/ScrollViewNativeComponentType';
1516

1617
import * as React from 'react';
17-
import View from 'react-native/Libraries/Components/View/View';
18-
import requireNativeComponent from 'react-native/Libraries/ReactNative/requireNativeComponent';
18+
19+
const {View, requireNativeComponent} =
20+
jest.requireActual<TReactNative>('react-native');
1921

2022
const mockComponent =
2123
jest.requireActual<TmockComponent>('../mockComponent').default;
2224
const MockNativeMethods = jest.requireActual<TMockNativeMethods>(
2325
'../MockNativeMethods',
2426
).default;
2527

26-
const RCTScrollView =
27-
requireNativeComponent<ScrollViewNativeProps>('RCTScrollView');
28+
const RCTScrollView = requireNativeComponent<ScrollViewProps>('RCTScrollView');
2829

2930
const BaseComponent = mockComponent(
3031
'react-native/Libraries/Components/ScrollView/ScrollView',

‎packages/jest-preset/jest/mocks/requireNativeComponent.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow strict
7+
* @flow strict-local
88
* @format
99
*/
1010

1111
import typeof * as TmockNativeComponent from '../mockNativeComponent';
12-
import type {HostComponent} from 'react-native/src/private/types/HostComponent';
12+
import type {HostComponent} from 'react-native';
1313

1414
const mockNativeComponent = jest.requireActual<TmockNativeComponent>(
1515
'../mockNativeComponent',

‎packages/jest-preset/jest/mocks/useColorScheme.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow strict
7+
* @flow strict-local
88
* @format
99
*/
1010

11-
import type {ColorSchemeName} from 'react-native/Libraries/Utilities/NativeAppearance';
11+
import type {ColorSchemeName} from 'react-native';
1212

1313
const useColorScheme = jest.fn(() => 'light') as JestMockFn<
1414
[],

0 commit comments

Comments
 (0)