Move fabric dependecies out of OSS instrumentation tests (#21306)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/21306 This diff moves fabric dependencies out of OSS instrumentation tests (js/react-native-github/ReactAndroid/src/androidTest/java/com/facebook/react/testing/BUCK), this will un-break build of OSS project in CI. Reviewed By: rsnara Differential Revision: D10020517 fbshipit-source-id: e2cf23afeeecf4cfb41345742f59c16af6b108d0
This commit is contained in:
Родитель
783cb8e4a6
Коммит
a5f1d79adf
|
@ -13,8 +13,6 @@ rn_android_library(
|
||||||
"PUBLIC",
|
"PUBLIC",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
react_native_dep("java/com/facebook/fbreact/fabricxx:fabricxx"),
|
|
||||||
react_native_dep("java/com/facebook/fbreact/fabricxx/jsi:jsi"),
|
|
||||||
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
|
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
|
||||||
react_native_dep("third-party/android/support/v4:lib-support-v4"),
|
react_native_dep("third-party/android/support/v4:lib-support-v4"),
|
||||||
react_native_dep("third-party/java/buck-android-support:buck-android-support"),
|
react_native_dep("third-party/java/buck-android-support:buck-android-support"),
|
||||||
|
@ -39,5 +37,3 @@ rn_android_library(
|
||||||
react_native_target("res:uimanager"),
|
react_native_target("res:uimanager"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# /Users/dvacca/fbsource/fbandroid/xplat_cell/ReactAndroid/src/androidTest/java/com/facebook/react/testing/BUCK
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
*
|
||||||
|
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
||||||
|
* directory of this source tree.
|
||||||
|
*/
|
||||||
|
package com.facebook.react.testing;
|
||||||
|
|
||||||
|
import com.facebook.react.bridge.JavaScriptContextHolder;
|
||||||
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
|
import com.facebook.react.bridge.UIManager;
|
||||||
|
import com.facebook.react.uimanager.ViewManagerRegistry;
|
||||||
|
|
||||||
|
/** Factory used to create FabricUIManager in Testing infrastructure. */
|
||||||
|
public interface FabricUIManagerFactory {
|
||||||
|
|
||||||
|
UIManager getFabricUIManager(
|
||||||
|
ReactApplicationContext reactApplicationContext,
|
||||||
|
ViewManagerRegistry viewManagerRegistry,
|
||||||
|
JavaScriptContextHolder jsContext);
|
||||||
|
}
|
|
@ -15,7 +15,6 @@ import android.support.v4.app.FragmentActivity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import com.facebook.fbreact.fabricxx.jsi.Binding;
|
|
||||||
import com.facebook.infer.annotation.Assertions;
|
import com.facebook.infer.annotation.Assertions;
|
||||||
import com.facebook.react.ReactInstanceManager;
|
import com.facebook.react.ReactInstanceManager;
|
||||||
import com.facebook.react.ReactInstanceManagerBuilder;
|
import com.facebook.react.ReactInstanceManagerBuilder;
|
||||||
|
@ -29,8 +28,6 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReactContext;
|
import com.facebook.react.bridge.ReactContext;
|
||||||
import com.facebook.react.bridge.UIManager;
|
import com.facebook.react.bridge.UIManager;
|
||||||
import com.facebook.react.common.LifecycleState;
|
import com.facebook.react.common.LifecycleState;
|
||||||
import com.facebook.react.fabric.FabricBinder;
|
|
||||||
import com.facebook.react.fabric.FabricBinding;
|
|
||||||
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
||||||
import com.facebook.react.modules.core.PermissionAwareActivity;
|
import com.facebook.react.modules.core.PermissionAwareActivity;
|
||||||
import com.facebook.react.modules.core.PermissionListener;
|
import com.facebook.react.modules.core.PermissionListener;
|
||||||
|
@ -199,7 +196,7 @@ public class ReactAppTestActivity extends FragmentActivity
|
||||||
throw new RuntimeException("Layout never occurred for component " + appKey, e);}
|
throw new RuntimeException("Layout never occurred for component " + appKey, e);}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadBundle(ReactInstanceSpecForTest spec, String bundleName, boolean useDevSupport) {
|
public void loadBundle(final ReactInstanceSpecForTest spec, String bundleName, boolean useDevSupport) {
|
||||||
|
|
||||||
mBridgeIdleSignaler = new ReactBridgeIdleSignaler();
|
mBridgeIdleSignaler = new ReactBridgeIdleSignaler();
|
||||||
|
|
||||||
|
@ -243,25 +240,12 @@ public class ReactAppTestActivity extends FragmentActivity
|
||||||
return new JSIModuleProvider() {
|
return new JSIModuleProvider() {
|
||||||
@Override
|
@Override
|
||||||
public UIManager get() {
|
public UIManager get() {
|
||||||
List<ViewManager> viewManagers =
|
|
||||||
mReactInstanceManager.getOrCreateViewManagers(
|
|
||||||
reactApplicationContext);
|
|
||||||
EventDispatcher eventDispatcher =
|
|
||||||
reactApplicationContext
|
|
||||||
.getNativeModule(UIManagerModule.class)
|
|
||||||
.getEventDispatcher();
|
|
||||||
|
|
||||||
ViewManagerRegistry viewManagerRegistry =
|
ViewManagerRegistry viewManagerRegistry =
|
||||||
new ViewManagerRegistry(
|
new ViewManagerRegistry(
|
||||||
mReactInstanceManager.getOrCreateViewManagers(reactApplicationContext));
|
mReactInstanceManager.getOrCreateViewManagers(reactApplicationContext));
|
||||||
|
|
||||||
UIManager uiManager =
|
FabricUIManagerFactory factory = spec.getFabricUIManagerFactory();
|
||||||
new com.facebook.fbreact.fabricxx.UIManager(
|
return factory != null ? factory.getFabricUIManager(reactApplicationContext, viewManagerRegistry, jsContext) : null;
|
||||||
reactApplicationContext, viewManagerRegistry, jsContext);
|
|
||||||
|
|
||||||
FabricBinding binding = new Binding();
|
|
||||||
binding.installFabric(jsContext, (FabricBinder) uiManager);
|
|
||||||
return uiManager;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
||||||
* LICENSE file in the root directory of this source tree.
|
* directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.react.testing;
|
package com.facebook.react.testing;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
@ -31,6 +30,7 @@ public class ReactInstanceSpecForTest {
|
||||||
private final List<Class<? extends JavaScriptModule>> mJSModuleSpecs = new ArrayList<>();
|
private final List<Class<? extends JavaScriptModule>> mJSModuleSpecs = new ArrayList<>();
|
||||||
private final List<ViewManager> mViewManagers = new ArrayList<>();
|
private final List<ViewManager> mViewManagers = new ArrayList<>();
|
||||||
private final ArrayList<ReactPackage> mReactPackages = new ArrayList<>();
|
private final ArrayList<ReactPackage> mReactPackages = new ArrayList<>();
|
||||||
|
@Nullable private FabricUIManagerFactory mFabricUIManagerFactory = null;
|
||||||
@Nullable private JavaScriptExecutorFactory mJavaScriptExecutorFactory = null;
|
@Nullable private JavaScriptExecutorFactory mJavaScriptExecutorFactory = null;
|
||||||
|
|
||||||
public ReactInstanceSpecForTest addNativeModule(NativeModule module) {
|
public ReactInstanceSpecForTest addNativeModule(NativeModule module) {
|
||||||
|
@ -38,7 +38,8 @@ public class ReactInstanceSpecForTest {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReactInstanceSpecForTest setJavaScriptExecutorFactory(JavaScriptExecutorFactory javaScriptExecutorFactory) {
|
public ReactInstanceSpecForTest setJavaScriptExecutorFactory(
|
||||||
|
JavaScriptExecutorFactory javaScriptExecutorFactory) {
|
||||||
mJavaScriptExecutorFactory = javaScriptExecutorFactory;
|
mJavaScriptExecutorFactory = javaScriptExecutorFactory;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -52,6 +53,16 @@ public class ReactInstanceSpecForTest {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReactInstanceSpecForTest setFabricUIManagerFactory(@Nullable FabricUIManagerFactory fabricUIManagerFactory) {
|
||||||
|
mFabricUIManagerFactory = fabricUIManagerFactory;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public FabricUIManagerFactory getFabricUIManagerFactory() {
|
||||||
|
return mFabricUIManagerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
public ReactInstanceSpecForTest addPackages(List<ReactPackage> reactPackages) {
|
public ReactInstanceSpecForTest addPackages(List<ReactPackage> reactPackages) {
|
||||||
mReactPackages.addAll(reactPackages);
|
mReactPackages.addAll(reactPackages);
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
||||||
* LICENSE file in the root directory of this source tree.
|
* directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.react.testing;
|
package com.facebook.react.testing;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -20,17 +19,18 @@ import javax.annotation.Nullable;
|
||||||
/**
|
/**
|
||||||
* Base class for instrumentation tests that runs React based application.
|
* Base class for instrumentation tests that runs React based application.
|
||||||
*
|
*
|
||||||
* This is similar to ReactAppInstrumentationTestCase except ReactInstrumentationTest allows
|
* <p>This is similar to ReactAppInstrumentationTestCase except ReactInstrumentationTest allows
|
||||||
* optional rendering of components. A test case can render no components or render multiple
|
* optional rendering of components. A test case can render no components or render multiple
|
||||||
* components.
|
* components.
|
||||||
*/
|
*/
|
||||||
public abstract class ReactInstrumentationTest extends
|
public abstract class ReactInstrumentationTest
|
||||||
ActivityInstrumentationTestCase2<ReactAppTestActivity> implements IdleWaiter {
|
extends ActivityInstrumentationTestCase2<ReactAppTestActivity> implements IdleWaiter {
|
||||||
|
|
||||||
protected StringRecordingModule mRecordingModule;
|
protected StringRecordingModule mRecordingModule;
|
||||||
|
|
||||||
@Nullable
|
@Nullable protected FabricUIManagerFactory mFabricUIManagerFactory = null;
|
||||||
protected JavaScriptExecutorFactory mJavaScriptExecutorFactory = null;
|
|
||||||
|
@Nullable protected JavaScriptExecutorFactory mJavaScriptExecutorFactory = null;
|
||||||
|
|
||||||
public ReactInstrumentationTest() {
|
public ReactInstrumentationTest() {
|
||||||
super(ReactAppTestActivity.class);
|
super(ReactAppTestActivity.class);
|
||||||
|
@ -45,15 +45,10 @@ public abstract class ReactInstrumentationTest extends
|
||||||
setActivityIntent(intent);
|
setActivityIntent(intent);
|
||||||
mRecordingModule = new StringRecordingModule();
|
mRecordingModule = new StringRecordingModule();
|
||||||
final ReactAppTestActivity activity = getActivity();
|
final ReactAppTestActivity activity = getActivity();
|
||||||
activity.loadBundle(
|
activity.loadBundle(createReactInstanceSpecForTest(), getBundleName(), getEnableDevSupport());
|
||||||
createReactInstanceSpecForTest(),
|
|
||||||
getBundleName(),
|
|
||||||
getEnableDevSupport());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Renders this component within this test's activity */
|
||||||
* Renders this component within this test's activity
|
|
||||||
*/
|
|
||||||
public void renderComponent(final String componentName) {
|
public void renderComponent(final String componentName) {
|
||||||
getActivity().renderComponent(componentName, null);
|
getActivity().renderComponent(componentName, null);
|
||||||
waitForBridgeAndUIIdle();
|
waitForBridgeAndUIIdle();
|
||||||
|
@ -71,8 +66,8 @@ public abstract class ReactInstrumentationTest extends
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends View> T getViewByTestId(String testID) {
|
public <T extends View> T getViewByTestId(String testID) {
|
||||||
return (T) ReactTestHelper
|
return (T)
|
||||||
.getViewWithReactTestId((ViewGroup) getRootView().getParent(), testID);
|
ReactTestHelper.getViewWithReactTestId((ViewGroup) getRootView().getParent(), testID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SingleTouchGestureGenerator createGestureGenerator() {
|
public SingleTouchGestureGenerator createGestureGenerator() {
|
||||||
|
@ -99,21 +94,20 @@ public abstract class ReactInstrumentationTest extends
|
||||||
return getReactContext().getJSModule(jsInterface);
|
return getReactContext().getJSModule(jsInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Override this method to provide extra native modules to be loaded before the app starts */
|
||||||
* Override this method to provide extra native modules to be loaded before the app starts
|
|
||||||
*/
|
|
||||||
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
|
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
|
||||||
ReactInstanceSpecForTest reactInstanceSpecForTest =
|
ReactInstanceSpecForTest reactInstanceSpecForTest =
|
||||||
new ReactInstanceSpecForTest().addNativeModule(mRecordingModule);
|
new ReactInstanceSpecForTest().addNativeModule(mRecordingModule);
|
||||||
if (mJavaScriptExecutorFactory != null) {
|
if (mJavaScriptExecutorFactory != null) {
|
||||||
reactInstanceSpecForTest.setJavaScriptExecutorFactory(mJavaScriptExecutorFactory);
|
reactInstanceSpecForTest.setJavaScriptExecutorFactory(mJavaScriptExecutorFactory);
|
||||||
}
|
}
|
||||||
|
if (mFabricUIManagerFactory != null) {
|
||||||
|
reactInstanceSpecForTest.setFabricUIManagerFactory(mFabricUIManagerFactory);
|
||||||
|
}
|
||||||
return reactInstanceSpecForTest;
|
return reactInstanceSpecForTest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Implement this method to provide the bundle for this test */
|
||||||
* Implement this method to provide the bundle for this test
|
|
||||||
*/
|
|
||||||
protected abstract String getBundleName();
|
protected abstract String getBundleName();
|
||||||
|
|
||||||
protected ReactContext getReactContext() {
|
protected ReactContext getReactContext() {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче