Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module.exports = {
'<rootDir>/packages/react-native/src/react-private-interface.js',
'^react-native/setup-env$':
'<rootDir>/packages/react-native/src/setup-env.js',
'^react-native/unstable-internals-do-not-use$':
'<rootDir>/packages/react-native/src/unstable-internals-do-not-use.js',
},
setupFiles: ['./packages/jest-preset/jest/local-setup.js'],
fakeTimers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ interface NativeCommands {
+seek: (viewRef: React.ElementRef<NativeType>, position: number) => void,
+stop: (viewRef: React.ElementRef<NativeType>) => void,
}
const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry');
const {
NativeComponentRegistry
} = require('react-native');
let nativeComponentName = 'Module';
export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"Module\\",
Expand All @@ -39,7 +41,9 @@ interface NativeCommands {
+pause: (viewRef: React.ElementRef<NativeType>) => void,
+play: (viewRef: React.ElementRef<NativeType>) => void,
}
const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry');
const {
NativeComponentRegistry
} = require('react-native');
let nativeComponentName = 'Module';
export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"Module\\",
Expand All @@ -63,7 +67,9 @@ interface NativeCommands {
+mute: (viewRef: React.ElementRef<NativeType>) => void,
+unmute: (viewRef: React.ElementRef<NativeType>) => void,
}
const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry');
const {
NativeComponentRegistry
} = require('react-native');
let nativeComponentName = 'Module';
export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"Module\\",
Expand Down Expand Up @@ -93,13 +99,16 @@ interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void,
+scrollTo: (viewRef: React.ElementRef<NativeType>, y: Int32, animated: boolean) => void,
}
const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry');
const {
ConditionallyIgnoredEventHandlers
} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore');
} = require('react-native/unstable-internals-do-not-use');
const {
dispatchCommand
} = require(\\"react-native/Libraries/ReactNative/RendererProxy\\");
NativeComponentRegistry
} = require('react-native');
const {
findNodeHandle,
UIManager
} = require(\\"react-native\\");
let nativeComponentName = 'RCTModule';
export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"RCTModule\\",
Expand Down Expand Up @@ -127,10 +136,10 @@ export const __INTERNAL_VIEW_CONFIG = {
export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG);
export const Commands = {
hotspotUpdate(ref, x, y) {
dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]);
UIManager.dispatchViewManagerCommand(findNodeHandle(ref), \\"hotspotUpdate\\", [x, y]);
},
scrollTo(ref, y, animated) {
dispatchCommand(ref, \\"scrollTo\\", [y, animated]);
UIManager.dispatchViewManagerCommand(findNodeHandle(ref), \\"scrollTo\\", [y, animated]);
}
};"
`;
Expand All @@ -156,13 +165,16 @@ interface NativeCommands {
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void,
+scrollTo: (viewRef: React.ElementRef<NativeType>, y: Int32, animated: boolean) => void,
}
const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/NativeComponentRegistry');
const {
ConditionallyIgnoredEventHandlers
} = require('react-native/Libraries/NativeComponent/ViewConfigIgnore');
} = require('react-native/unstable-internals-do-not-use');
const {
NativeComponentRegistry
} = require('react-native');
const {
dispatchCommand
} = require(\\"react-native/Libraries/ReactNative/RendererProxy\\");
findNodeHandle,
UIManager
} = require(\\"react-native\\");
let nativeComponentName = 'RCTModule';
export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: \\"RCTModule\\",
Expand Down Expand Up @@ -190,10 +202,10 @@ export const __INTERNAL_VIEW_CONFIG = {
export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG);
export const Commands = {
hotspotUpdate(ref, x, y) {
dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]);
UIManager.dispatchViewManagerCommand(findNodeHandle(ref), \\"hotspotUpdate\\", [x, y]);
},
scrollTo(ref, y, animated) {
dispatchCommand(ref, \\"scrollTo\\", [y, animated]);
UIManager.dispatchViewManagerCommand(findNodeHandle(ref), \\"scrollTo\\", [y, animated]);
}
};"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ const eslintTester = new ESLintTester();
const VALID_SPECS = [
{
code: `
import {TurboModuleRegistry, type TurboModule} from 'react-native';
import type {UnsafeObject} from 'react-native/Libraries/Types/CodegenTypes';
import {TurboModuleRegistry, type CodegenTypes, type TurboModule} from 'react-native';
export interface Spec extends TurboModule {
func1(a: string): UnsafeObject,
func1(a: string): CodegenTypes.UnsafeObject,
}
export default TurboModuleRegistry.get<Spec>('XYZ');
`,
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-preset/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ module.exports = {
platforms: ['android', 'ios', 'native'],
},
moduleNameMapper: {
// `setup-env` and `react-private-interface` are secondary entry points
// exposed via the package's `exports`, but `./jest/resolver.js` strips
// `exports` and the generic mapper below resolves subpaths as literal
// directory paths. Alias them explicitly so they resolve to their `src/`
// implementations.
// These secondary entry points are exposed via the package's `exports`,
// but `./jest/resolver.js` strips `exports` and the generic mapper below
// resolves subpaths as literal directory paths. Alias them explicitly so
// they resolve to their `src/` implementations.
'^react-native/react-private-interface$': `${path.dirname(require.resolve('react-native'))}/src/react-private-interface.js`,
'^react-native/setup-env$': `${path.dirname(require.resolve('react-native'))}/src/setup-env.js`,
'^react-native/unstable-internals-do-not-use$': `${path.dirname(require.resolve('react-native'))}/src/unstable-internals-do-not-use.js`,
'^react-native($|/.*)': `${path.dirname(require.resolve('react-native'))}/$1`,
},
resolver: require.resolve('./jest/resolver.js'),
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-preset/jest/RefreshControlMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

'use strict';

import type {HostComponent} from 'react-native/src/private/types/HostComponent';
import type {HostComponent} from '../../react-native/src/private/types/HostComponent';

import requireNativeComponent from '../../react-native/Libraries/ReactNative/requireNativeComponent';
import * as React from 'react';
import requireNativeComponent from 'react-native/Libraries/ReactNative/requireNativeComponent';

const RCTRefreshControl: HostComponent<{}> = requireNativeComponent<{}>(
'RCTRefreshControl',
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/__tests__/setup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @format
*/

import NativeExceptionsManager from 'react-native/Libraries/Core/NativeExceptionsManager';
import NativeExceptionsManager from '../../../react-native/Libraries/Core/NativeExceptionsManager';

test('NativeExceptionsManager is a mock', () => {
expect(jest.isMockFunction(NativeExceptionsManager.reportException)).toBe(
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mockNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @format
*/

import type {HostInstance} from 'react-native/src/private/types/HostInstance';
import type {HostInstance} from '../../react-native/src/private/types/HostInstance';

import * as React from 'react';
import {createElement} from 'react';
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-preset/jest/mocks/ActivityIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
*/

import typeof * as TmockComponent from '../mockComponent';
import typeof TActivityIndicator from 'react-native/Libraries/Components/ActivityIndicator/ActivityIndicator';
import typeof {ActivityIndicator as TActivityIndicator} from 'react-native';

const mockComponent =
jest.requireActual<TmockComponent>('../mockComponent').default;

const ActivityIndicator = mockComponent(
'react-native/Libraries/Components/ActivityIndicator/ActivityIndicator',
'../../react-native/Libraries/Components/ActivityIndicator/ActivityIndicator',
null, // instanceMethods
true, // isESModule
) as TActivityIndicator;
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-preset/jest/mocks/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
*/

import typeof * as TmockComponent from '../mockComponent';
import typeof TImage from 'react-native/Libraries/Image/Image';
import typeof {Image as TImage} from 'react-native';

const mockComponent =
jest.requireActual<TmockComponent>('../mockComponent').default;

const Image = mockComponent(
'react-native/Libraries/Image/Image',
'../../react-native/Libraries/Image/Image',
null, // instanceMethods
true, // isESModule
) as TImage;
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-preset/jest/mocks/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
*/

import typeof * as TmockComponent from '../mockComponent';
import type {ModalProps} from 'react-native/Libraries/Modal/Modal';
import type {ModalProps} from 'react-native';

const mockComponent =
jest.requireActual<TmockComponent>('../mockComponent').default;

type TModal = component(...ModalProps);

const BaseComponent = mockComponent(
'react-native/Libraries/Modal/Modal',
'../../react-native/Libraries/Modal/Modal',
null, // instanceMethods
true, // isESModule
) as TModal;
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-preset/jest/mocks/RefreshControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* @format
*/

import type {RefreshControlProps} from 'react-native/Libraries/Components/RefreshControl/RefreshControl';
import type {HostComponent} from 'react-native/src/private/types/HostComponent';
import type {HostComponent} from '../../../react-native/src/private/types/HostComponent';
import type {RefreshControlProps} from 'react-native';

import requireNativeComponent from '../../../react-native/Libraries/ReactNative/requireNativeComponent';
import * as React from 'react';
import requireNativeComponent from 'react-native/Libraries/ReactNative/requireNativeComponent';

const RCTRefreshControl: HostComponent<{}> = requireNativeComponent<{}>(
'RCTRefreshControl',
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-preset/jest/mocks/RendererProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

import typeof * as TRendererImplementation from 'react-native/Libraries/ReactNative/RendererImplementation';
import typeof * as TRendererImplementation from '../../../react-native/Libraries/ReactNative/RendererImplementation';

const {
dispatchCommand,
Expand All @@ -24,7 +24,7 @@ const {
renderElement,
sendAccessibilityEvent,
} = jest.requireActual<TRendererImplementation>(
'react-native/Libraries/ReactNative/RendererImplementation',
'../../../react-native/Libraries/ReactNative/RendererImplementation',
) as TRendererImplementation;

export {
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-preset/jest/mocks/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
* @format
*/

import type {ScrollViewNativeProps} from '../../../react-native/Libraries/Components/ScrollView/ScrollViewNativeComponentType';
import typeof * as TmockComponent from '../mockComponent';
import typeof * as TMockNativeMethods from '../MockNativeMethods';
import typeof TScrollView from 'react-native/Libraries/Components/ScrollView/ScrollView';
import type {ScrollViewNativeProps} from 'react-native/Libraries/Components/ScrollView/ScrollViewNativeComponentType';
import typeof {ScrollView as TScrollView} from 'react-native';

import View from '../../../react-native/Libraries/Components/View/View';
import requireNativeComponent from '../../../react-native/Libraries/ReactNative/requireNativeComponent';
import * as React from 'react';
import View from 'react-native/Libraries/Components/View/View';
import requireNativeComponent from 'react-native/Libraries/ReactNative/requireNativeComponent';

const mockComponent =
jest.requireActual<TmockComponent>('../mockComponent').default;
Expand All @@ -27,7 +27,7 @@ const RCTScrollView =
requireNativeComponent<ScrollViewNativeProps>('RCTScrollView');

const BaseComponent = mockComponent(
'react-native/Libraries/Components/ScrollView/ScrollView',
'../../react-native/Libraries/Components/ScrollView/ScrollView',
{
...MockNativeMethods,
getScrollResponder: jest.fn(),
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-preset/jest/mocks/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import typeof * as TmockComponent from '../mockComponent';
import typeof * as TMockNativeMethods from '../MockNativeMethods';
import typeof TText from 'react-native/Libraries/Text/Text';
import typeof {Text as TText} from 'react-native';

const mockComponent =
jest.requireActual<TmockComponent>('../mockComponent').default;
Expand All @@ -19,7 +19,7 @@ const MockNativeMethods = jest.requireActual<TMockNativeMethods>(
).default;

const Text = mockComponent(
'react-native/Libraries/Text/Text',
'../../react-native/Libraries/Text/Text',
MockNativeMethods, // instanceMethods
true, // isESModule
) as TText;
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-preset/jest/mocks/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import typeof * as TmockComponent from '../mockComponent';
import typeof * as TMockNativeMethods from '../MockNativeMethods';
import typeof TTextInput from 'react-native/Libraries/Components/TextInput/TextInput';
import typeof {TextInput as TTextInput} from 'react-native';

const mockComponent =
jest.requireActual<TmockComponent>('../mockComponent').default;
Expand All @@ -19,7 +19,7 @@ const MockNativeMethods = jest.requireActual<TMockNativeMethods>(
).default;

const TextInput = mockComponent(
'react-native/Libraries/Components/TextInput/TextInput',
'../../react-native/Libraries/Components/TextInput/TextInput',
{
...MockNativeMethods,
isFocused: jest.fn(),
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-preset/jest/mocks/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import typeof * as TmockComponent from '../mockComponent';
import typeof * as TMockNativeMethods from '../MockNativeMethods';
import typeof TView from 'react-native/Libraries/Components/View/View';
import typeof {View as TView} from 'react-native';

const mockComponent =
jest.requireActual<TmockComponent>('../mockComponent').default;
Expand All @@ -19,7 +19,7 @@ const MockNativeMethods = jest.requireActual<TMockNativeMethods>(
).default;

const View = mockComponent(
'react-native/Libraries/Components/View/View',
'../../react-native/Libraries/Components/View/View',
MockNativeMethods, // instanceMethods
true, // isESModule
) as TView;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/ViewNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @format
*/

import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';
import type {ViewProps} from 'react-native';

import * as React from 'react';
import {createElement} from 'react';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/requireNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* @format
*/

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

const mockNativeComponent = jest.requireActual<TmockNativeComponent>(
'../mockNativeComponent',
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset/jest/mocks/useColorScheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @format
*/

import type {ColorSchemeName} from 'react-native/Libraries/Utilities/NativeAppearance';
import type {ColorSchemeName} from '../../../react-native/Libraries/Utilities/NativeAppearance';

const useColorScheme = jest.fn(() => 'light') as JestMockFn<
[],
Expand Down
Loading
Loading