Add fb4a native modules to snapshot tests

Reviewed By: achen1

Differential Revision: D5599659

fbshipit-source-id: ca9f8806212e6b3551eaebb95903bc168110b4ec
This commit is contained in:
Spencer Ahrens 2017-08-25 19:05:44 -07:00 committed by Facebook Github Bot
parent 5d58831eac
commit dc22bd638f
3 changed files with 46 additions and 24 deletions

View File

@ -8,18 +8,12 @@
package com.facebook.react.testing; package com.facebook.react.testing;
import javax.annotation.Nullable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentActivity; 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.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;
@ -31,6 +25,9 @@ import com.facebook.react.shell.MainReactPackage;
import com.facebook.react.testing.idledetection.ReactBridgeIdleSignaler; import com.facebook.react.testing.idledetection.ReactBridgeIdleSignaler;
import com.facebook.react.testing.idledetection.ReactIdleDetectionUtil; import com.facebook.react.testing.idledetection.ReactIdleDetectionUtil;
import com.facebook.react.uimanager.UIImplementationProvider; import com.facebook.react.uimanager.UIImplementationProvider;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
public class ReactAppTestActivity extends FragmentActivity implements public class ReactAppTestActivity extends FragmentActivity implements
DefaultHardwareBackBtnHandler DefaultHardwareBackBtnHandler
@ -39,7 +36,7 @@ public class ReactAppTestActivity extends FragmentActivity implements
private static final String DEFAULT_BUNDLE_NAME = "AndroidTestBundle.js"; private static final String DEFAULT_BUNDLE_NAME = "AndroidTestBundle.js";
private static final int ROOT_VIEW_ID = 8675309; private static final int ROOT_VIEW_ID = 8675309;
// we need a bigger timeout for CI builds because they run on a slow emulator // we need a bigger timeout for CI builds because they run on a slow emulator
private static final long IDLE_TIMEOUT_MS = 60000; private static final long IDLE_TIMEOUT_MS = 120000;
private CountDownLatch mLayoutEvent = new CountDownLatch(1); private CountDownLatch mLayoutEvent = new CountDownLatch(1);
private @Nullable ReactBridgeIdleSignaler mBridgeIdleSignaler; private @Nullable ReactBridgeIdleSignaler mBridgeIdleSignaler;
@ -164,16 +161,21 @@ public class ReactAppTestActivity extends FragmentActivity implements
mBridgeIdleSignaler = new ReactBridgeIdleSignaler(); mBridgeIdleSignaler = new ReactBridgeIdleSignaler();
ReactInstanceManagerBuilder builder = ReactInstanceManagerBuilder builder =
ReactTestHelper.getReactTestFactory().getReactInstanceManagerBuilder() ReactTestHelper.getReactTestFactory()
.setApplication(getApplication()) .getReactInstanceManagerBuilder()
.setBundleAssetName(bundleName) .setApplication(getApplication())
.setBundleAssetName(bundleName);
if (!spec.getAlternativeReactPackagesForTest().isEmpty()) {
builder.addPackages(spec.getAlternativeReactPackagesForTest());
} else {
builder.addPackage(new MainReactPackage());
}
builder
.addPackage(new InstanceSpecForTestPackage(spec))
// By not setting a JS module name, we force the bundle to be always loaded from // By not setting a JS module name, we force the bundle to be always loaded from
// assets, not the devserver, even if dev mode is enabled (such as when testing redboxes). // assets, not the devserver, even if dev mode is enabled (such as when testing redboxes).
// This makes sense because we never run the devserver in tests. // This makes sense because we never run the devserver in tests.
//.setJSMainModuleName() //.setJSMainModuleName()
.addPackage(spec.getAlternativeReactPackageForTest() != null ?
spec.getAlternativeReactPackageForTest() : new MainReactPackage())
.addPackage(new InstanceSpecForTestPackage(spec))
.setUseDeveloperSupport(useDevSupport) .setUseDeveloperSupport(useDevSupport)
.setBridgeIdleDebugListener(mBridgeIdleSignaler) .setBridgeIdleDebugListener(mBridgeIdleSignaler)
.setInitialLifecycleState(mLifecycleState) .setInitialLifecycleState(mLifecycleState)

View File

@ -8,17 +8,15 @@
package com.facebook.react.testing; package com.facebook.react.testing;
import android.annotation.SuppressLint;
import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import android.annotation.SuppressLint;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.ReactPackage;
/** /**
* A spec that allows a test to add additional NativeModules/JS modules to the ReactInstance. This * A spec that allows a test to add additional NativeModules/JS modules to the ReactInstance. This
* can also be used to stub out existing native modules by adding another module with the same name * can also be used to stub out existing native modules by adding another module with the same name
@ -31,7 +29,7 @@ public class ReactInstanceSpecForTest {
new ArrayList<NativeModule>(Arrays.asList(new FakeWebSocketModule())); new ArrayList<NativeModule>(Arrays.asList(new FakeWebSocketModule()));
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 ReactPackage mReactPackage = null; private final ArrayList<ReactPackage> mReactPackages = new ArrayList<>();
public ReactInstanceSpecForTest addNativeModule(NativeModule module) { public ReactInstanceSpecForTest addNativeModule(NativeModule module) {
mNativeModules.add(module); mNativeModules.add(module);
@ -39,7 +37,16 @@ public class ReactInstanceSpecForTest {
} }
public ReactInstanceSpecForTest setPackage(ReactPackage reactPackage) { public ReactInstanceSpecForTest setPackage(ReactPackage reactPackage) {
mReactPackage = reactPackage; if (!mReactPackages.isEmpty()) {
throw new IllegalStateException(
"setPackage is not allowed after addPackages. " + reactPackage);
}
mReactPackages.add(reactPackage);
return this;
}
public ReactInstanceSpecForTest addPackages(List<ReactPackage> reactPackages) {
mReactPackages.addAll(reactPackages);
return this; return this;
} }
@ -53,7 +60,15 @@ public class ReactInstanceSpecForTest {
} }
public ReactPackage getAlternativeReactPackageForTest() { public ReactPackage getAlternativeReactPackageForTest() {
return mReactPackage; if (mReactPackages.size() > 1) {
throw new IllegalStateException(
"Multiple packages were added - use getAlternativeReactPackagesForTest instead.");
}
return mReactPackages.get(0);
}
public List<ReactPackage> getAlternativeReactPackagesForTest() {
return mReactPackages;
} }
public List<ViewManager> getExtraViewManagers() { public List<ViewManager> getExtraViewManagers() {

View File

@ -5,9 +5,9 @@ package com.facebook.react;
import android.app.Activity; import android.app.Activity;
import android.app.Application; import android.app.Application;
import com.facebook.infer.annotation.Assertions; import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.bridge.JSBundleLoader; import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.bridge.JSCJavaScriptExecutorFactory; import com.facebook.react.bridge.JSCJavaScriptExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.bridge.NativeModuleCallExceptionHandler; import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener; import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
import com.facebook.react.common.LifecycleState; import com.facebook.react.common.LifecycleState;
@ -125,6 +125,11 @@ public class ReactInstanceManagerBuilder {
return this; return this;
} }
public ReactInstanceManagerBuilder addPackages(List<ReactPackage> reactPackages) {
mPackages.addAll(reactPackages);
return this;
}
public ReactInstanceManagerBuilder setBridgeIdleDebugListener( public ReactInstanceManagerBuilder setBridgeIdleDebugListener(
NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener) { NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener) {
mBridgeIdleDebugListener = bridgeIdleDebugListener; mBridgeIdleDebugListener = bridgeIdleDebugListener;