From 55a15f620aa2308b63a4c87c37f76373b3661606 Mon Sep 17 00:00:00 2001 From: Jeff Payan Date: Wed, 28 Aug 2019 16:11:26 -0700 Subject: [PATCH 1/2] remove dependencies on haste modules --- src/preset/configure.js | 34 +++++++++++++++++----------------- src/preset/mock-modules.js | 24 +++++++++++++----------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/preset/configure.js b/src/preset/configure.js index 385b308..30fe655 100644 --- a/src/preset/configure.js +++ b/src/preset/configure.js @@ -16,23 +16,23 @@ configureNTL({ // Query lists coreComponents: [ - 'ActivityIndicator', - 'Button', - 'DrawerLayoutAndroid', - 'Image', - 'Modal', - 'Picker', - 'RefreshControl', - 'SafeAreaView', - 'ScrollView', - 'Switch', - 'Text', - 'TextInput', - 'TouchableHighlight', - 'TouchableNativeFeedback', - 'TouchableOpacity', - 'TouchableWithoutFeedback', - 'View', + 'react-native/Libraries/Components/ActivityIndicator/ActivityIndicator', + 'react-native/Libraries/Components/Button', + 'react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid', + 'react-native/Libraries/Image/Image', + 'react-native/Libraries/Modal/Modal', + 'react-native/Libraries/Components/Picker/Picker', + 'react-native/Libraries/Components/RefreshControl/RefreshControl', + 'react-native/Libraries/Components/SafeAreaView/SafeAreaView', + 'react-native/Libraries/Components/ScrollView/ScrollView', + 'react-native/Libraries/Components/Switch/Switch', + 'react-native/Libraries/Text/Text', + 'react-native/Libraries/Components/TextInput/TextInput', + 'react-native/Libraries/Components/Touchable/TouchableHighlight', + 'react-native/Libraries/Components/Touchable/TouchableNativeFeedback', + 'react-native/Libraries/Components/Touchable/TouchableOpacity', + 'react-native/Libraries/Components/Touchable/TouchableWithoutFeedback', + 'react-native/Libraries/Components/View/View', ], displayValueComponents: ['TextInput', 'Picker', 'Switch'], textComponents: ['Button', 'Text', 'TextInput'], diff --git a/src/preset/mock-modules.js b/src/preset/mock-modules.js index 20e4bb7..14528e8 100644 --- a/src/preset/mock-modules.js +++ b/src/preset/mock-modules.js @@ -13,7 +13,7 @@ getConfig('coreComponents').forEach(component => { }); // Un-mock ReactNative so we can hide annoying `console.warn`s -jest.unmock('ReactNative'); +jest.unmock('react-native/Libraries/Renderer/shims/ReactNative'); // Mock the components we want mocked getConfig('coreComponents').forEach(component => { @@ -23,21 +23,23 @@ getConfig('coreComponents').forEach(component => { }); // Mock the Picker one-off because it's kinda weird -jest.doMock('Picker', () => { +jest.doMock('react-native/Libraries/Components/Picker/Picker', () => { const React = jest.requireActual('react'); - const Picker = mockComponent('Picker'); + const Picker = mockComponent('react-native/Libraries/Components/Picker/Picker'); Picker.Item = ({ children, ...props }) => React.createElement('Picker.Item', props, children); return Picker; }); // Re-mock ReactNative with native methods mocked -jest.mock('NativeAnimatedHelper').doMock('ReactNative', () => { - const ReactNative = jest.requireActual('ReactNative'); - const NativeMethodsMixin = - ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativeMethodsMixin; +jest + .mock('NativeAnimatedHelper') + .doMock('react-native/Libraries/Renderer/shims/ReactNative', () => { + const ReactNative = jest.requireActual('react-native/Libraries/Renderer/shims/ReactNative'); + const NativeMethodsMixin = + ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativeMethodsMixin; - Object.assign(NativeMethodsMixin, mockNativeMethods); - Object.assign(ReactNative.NativeComponent.prototype, mockNativeMethods); + Object.assign(NativeMethodsMixin, mockNativeMethods); + Object.assign(ReactNative.NativeComponent.prototype, mockNativeMethods); - return ReactNative; -}); + return ReactNative; + }); From 934a9e4c21fa0ce72ed188fd1e2681401291f38e Mon Sep 17 00:00:00 2001 From: Jeff Payan Date: Wed, 28 Aug 2019 16:25:43 -0700 Subject: [PATCH 2/2] fixed missing haste modules --- examples/__tests__/react-navigation.js | 20 +++++++++++--------- src/preset/mock-modules.js | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/__tests__/react-navigation.js b/examples/__tests__/react-navigation.js index e123b5d..1be2baa 100644 --- a/examples/__tests__/react-navigation.js +++ b/examples/__tests__/react-navigation.js @@ -5,15 +5,17 @@ import { createStackNavigator, createAppContainer, withNavigation } from 'react- import { render, fireEvent } from '../../src'; -jest.mock('NativeAnimatedHelper').mock('react-native-gesture-handler', () => { - const View = require('react-native').View; - return { - State: {}, - PanGestureHandler: View, - BaseButton: View, - Directions: {}, - }; -}); +jest + .mock('react-native/Libraries/Animated/src/NativeAnimatedHelper') + .mock('react-native-gesture-handler', () => { + const View = require('react-native').View; + return { + State: {}, + PanGestureHandler: View, + BaseButton: View, + Directions: {}, + }; + }); const Home = ({ navigation }) => ( diff --git a/src/preset/mock-modules.js b/src/preset/mock-modules.js index 14528e8..566bc78 100644 --- a/src/preset/mock-modules.js +++ b/src/preset/mock-modules.js @@ -32,7 +32,7 @@ jest.doMock('react-native/Libraries/Components/Picker/Picker', () => { // Re-mock ReactNative with native methods mocked jest - .mock('NativeAnimatedHelper') + .mock('react-native/Libraries/Animated/src/NativeAnimatedHelper') .doMock('react-native/Libraries/Renderer/shims/ReactNative', () => { const ReactNative = jest.requireActual('react-native/Libraries/Renderer/shims/ReactNative'); const NativeMethodsMixin =