mirror of
https://github.com/react/react-native.git
synced 2026-09-28 05:13:06 +08:00
Complete remaining deep import migration (#58673)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/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
This commit is contained in:
committed by
meta-codesync[bot]
parent
f156ef2b02
commit
765d153ece
@@ -10,10 +10,13 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {HostComponent} from 'react-native/src/private/types/HostComponent';
|
||||
import type {HostComponent} from 'react-native';
|
||||
import typeof * as TReactNative from 'react-native';
|
||||
|
||||
import * as React from 'react';
|
||||
import requireNativeComponent from 'react-native/Libraries/ReactNative/requireNativeComponent';
|
||||
|
||||
const {requireNativeComponent} =
|
||||
jest.requireActual<TReactNative>('react-native');
|
||||
|
||||
const RCTRefreshControl: HostComponent<{}> = requireNativeComponent<{}>(
|
||||
'RCTRefreshControl',
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import NativeExceptionsManager from 'react-native/Libraries/Core/NativeExceptionsManager';
|
||||
const NativeExceptionsManager = jest.requireMock(
|
||||
'react-native/Libraries/Core/NativeExceptionsManager',
|
||||
).default;
|
||||
|
||||
test('NativeAnimatedHelper is a mock', () => {
|
||||
const consoleWarn = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
@@ -40,3 +42,15 @@ test('NativeExceptionsManager is a mock', () => {
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test('native component mocks work with a partial react-native mock', () => {
|
||||
jest.isolateModules(() => {
|
||||
jest.doMock('react-native', () => ({}));
|
||||
|
||||
expect(() => {
|
||||
jest.requireActual<unknown>('../RefreshControlMock');
|
||||
jest.requireActual<unknown>('../mocks/RefreshControl');
|
||||
jest.requireActual<unknown>('../mocks/ScrollView');
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type {HostInstance} from 'react-native/src/private/types/HostInstance';
|
||||
import type {HostInstance} from 'react-native';
|
||||
|
||||
import * as React from 'react';
|
||||
import {createElement} from 'react';
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
import typeof TNativeAnimatedHelper from 'react-native/src/private/animated/NativeAnimatedHelper';
|
||||
|
||||
const NativeAnimatedHelper = jest.requireActual<{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type {RefreshControlProps} from 'react-native';
|
||||
import type {HostComponent} from 'react-native/src/private/types/HostComponent';
|
||||
import type {HostComponent, RefreshControlProps} from 'react-native';
|
||||
import typeof * as TReactNative from 'react-native';
|
||||
|
||||
import * as React from 'react';
|
||||
import requireNativeComponent from 'react-native/Libraries/ReactNative/requireNativeComponent';
|
||||
|
||||
const {requireNativeComponent} =
|
||||
jest.requireActual<TReactNative>('react-native');
|
||||
|
||||
const RCTRefreshControl: HostComponent<{}> = requireNativeComponent<{}>(
|
||||
'RCTRefreshControl',
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
// In tests, we can use the default version without dependency injection.
|
||||
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
import typeof * as TRendererImplementation from 'react-native/Libraries/ReactNative/RendererImplementation';
|
||||
|
||||
const {
|
||||
|
||||
@@ -10,12 +10,14 @@
|
||||
|
||||
import typeof * as TmockComponent from '../mockComponent';
|
||||
import typeof * as TMockNativeMethods from '../MockNativeMethods';
|
||||
import type {ScrollViewProps} from 'react-native';
|
||||
import typeof * as TReactNative from 'react-native';
|
||||
import typeof {ScrollView as TScrollView} from 'react-native';
|
||||
import type {ScrollViewNativeProps} from 'react-native/Libraries/Components/ScrollView/ScrollViewNativeComponentType';
|
||||
|
||||
import * as React from 'react';
|
||||
import View from 'react-native/Libraries/Components/View/View';
|
||||
import requireNativeComponent from 'react-native/Libraries/ReactNative/requireNativeComponent';
|
||||
|
||||
const {View, requireNativeComponent} =
|
||||
jest.requireActual<TReactNative>('react-native');
|
||||
|
||||
const mockComponent =
|
||||
jest.requireActual<TmockComponent>('../mockComponent').default;
|
||||
@@ -23,8 +25,7 @@ const MockNativeMethods = jest.requireActual<TMockNativeMethods>(
|
||||
'../MockNativeMethods',
|
||||
).default;
|
||||
|
||||
const RCTScrollView =
|
||||
requireNativeComponent<ScrollViewNativeProps>('RCTScrollView');
|
||||
const RCTScrollView = requireNativeComponent<ScrollViewProps>('RCTScrollView');
|
||||
|
||||
const BaseComponent = mockComponent(
|
||||
'react-native/Libraries/Components/ScrollView/ScrollView',
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
import typeof * as TmockNativeComponent from '../mockNativeComponent';
|
||||
import type {HostComponent} from 'react-native/src/private/types/HostComponent';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
const mockNativeComponent = jest.requireActual<TmockNativeComponent>(
|
||||
'../mockNativeComponent',
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
import type {ColorSchemeName} from 'react-native/Libraries/Utilities/NativeAppearance';
|
||||
import type {ColorSchemeName} from 'react-native';
|
||||
|
||||
const useColorScheme = jest.fn(() => 'light') as JestMockFn<
|
||||
[],
|
||||
|
||||
@@ -87,96 +87,119 @@ try {
|
||||
} catch {}
|
||||
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/AppState/AppState',
|
||||
// $FlowFixMe[incompatible-type] - `./mocks/AppState` is incomplete.
|
||||
'm#./mocks/AppState',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/BatchedBridge/NativeModules',
|
||||
'm#./mocks/NativeModules',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo',
|
||||
'm#./mocks/AccessibilityInfo',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Components/ActivityIndicator/ActivityIndicator',
|
||||
'm#./mocks/ActivityIndicator',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Components/Clipboard/Clipboard',
|
||||
'm#./mocks/Clipboard',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Components/RefreshControl/RefreshControl',
|
||||
// $FlowFixMe[incompatible-type] - `react-native/Libraries/Components/RefreshControl/RefreshControl` should export a component type.
|
||||
'm#./mocks/RefreshControl',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Components/ScrollView/ScrollView',
|
||||
// $FlowFixMe[incompatible-exact] - `react-native/Libraries/Components/ScrollView/ScrollView` is... I don't even.
|
||||
// $FlowFixMe[incompatible-type]
|
||||
'm#./mocks/ScrollView',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Components/TextInput/TextInput',
|
||||
'm#./mocks/TextInput',
|
||||
);
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
mock('m#react-native/Libraries/Components/View/View', 'm#./mocks/View');
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Components/View/ViewNativeComponent',
|
||||
// $FlowFixMe[incompatible-type] - `./mocks/ViewNativeComponent` is incomplete.
|
||||
// $FlowFixMe[prop-missing]
|
||||
'm#./mocks/ViewNativeComponent',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Core/InitializeCore',
|
||||
'm#./mocks/InitializeCore',
|
||||
);
|
||||
mock('m#react-native/setup-env', 'm#./mocks/InitializeCore');
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
mock('m#react-native/Libraries/Core/NativeExceptionsManager');
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
mock('m#react-native/Libraries/Image/Image', 'm#./mocks/Image');
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Linking/Linking',
|
||||
// $FlowFixMe[incompatible-type] - `./mocks/Linking` is incomplete.
|
||||
'm#./mocks/Linking',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Modal/Modal',
|
||||
// $FlowFixMe[incompatible-type] - `react-native/Libraries/Modal/Modal` should export a component type.
|
||||
'm#./mocks/Modal',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/NativeComponent/NativeComponentRegistry',
|
||||
// $FlowFixMe[incompatible-type] - `./mocks/NativeComponentRegistry` should export named functions.
|
||||
'm#./mocks/NativeComponentRegistry',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/ReactNative/RendererProxy',
|
||||
// $FlowFixMe[incompatible-type] - `./mocks/RendererProxy` is incomplete.
|
||||
'm#./mocks/RendererProxy',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/ReactNative/requireNativeComponent',
|
||||
'm#./mocks/requireNativeComponent',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/ReactNative/UIManager',
|
||||
// $FlowFixMe[incompatible-type] - `./mocks/UIManager` is incomplete.
|
||||
'm#./mocks/UIManager',
|
||||
);
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
mock('m#react-native/Libraries/Text/Text', 'm#./mocks/Text');
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Utilities/useColorScheme',
|
||||
// $FlowFixMe[react-rule-hook-incompatible]
|
||||
'm#./mocks/useColorScheme',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/Libraries/Vibration/Vibration',
|
||||
// $FlowFixMe[incompatible-type]
|
||||
'm#./mocks/Vibration',
|
||||
);
|
||||
mock(
|
||||
// $FlowFixMe[cannot-resolve-module]
|
||||
'm#react-native/src/private/animated/NativeAnimatedHelper',
|
||||
'm#./mocks/NativeAnimatedHelper',
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user