Add fb4a native modules to snapshot tests
Reviewed By: achen1 Differential Revision: D5599659 fbshipit-source-id: ca9f8806212e6b3551eaebb95903bc168110b4ec
This commit is contained in:
parent
5d58831eac
commit
dc22bd638f
|
@ -8,18 +8,12 @@
|
|||
|
||||
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.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.ReactInstanceManager;
|
||||
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.ReactIdleDetectionUtil;
|
||||
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
|
||||
DefaultHardwareBackBtnHandler
|
||||
|
@ -39,7 +36,7 @@ public class ReactAppTestActivity extends FragmentActivity implements
|
|||
private static final String DEFAULT_BUNDLE_NAME = "AndroidTestBundle.js";
|
||||
private static final int ROOT_VIEW_ID = 8675309;
|
||||
// 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 @Nullable ReactBridgeIdleSignaler mBridgeIdleSignaler;
|
||||
|
@ -164,16 +161,21 @@ public class ReactAppTestActivity extends FragmentActivity implements
|
|||
mBridgeIdleSignaler = new ReactBridgeIdleSignaler();
|
||||
|
||||
ReactInstanceManagerBuilder builder =
|
||||
ReactTestHelper.getReactTestFactory().getReactInstanceManagerBuilder()
|
||||
.setApplication(getApplication())
|
||||
.setBundleAssetName(bundleName)
|
||||
ReactTestHelper.getReactTestFactory()
|
||||
.getReactInstanceManagerBuilder()
|
||||
.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
|
||||
// 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.
|
||||
//.setJSMainModuleName()
|
||||
.addPackage(spec.getAlternativeReactPackageForTest() != null ?
|
||||
spec.getAlternativeReactPackageForTest() : new MainReactPackage())
|
||||
.addPackage(new InstanceSpecForTestPackage(spec))
|
||||
.setUseDeveloperSupport(useDevSupport)
|
||||
.setBridgeIdleDebugListener(mBridgeIdleSignaler)
|
||||
.setInitialLifecycleState(mLifecycleState)
|
||||
|
|
|
@ -8,17 +8,15 @@
|
|||
|
||||
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.Arrays;
|
||||
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
|
||||
* 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()));
|
||||
private final List<Class<? extends JavaScriptModule>> mJSModuleSpecs = 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) {
|
||||
mNativeModules.add(module);
|
||||
|
@ -39,7 +37,16 @@ public class ReactInstanceSpecForTest {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -53,7 +60,15 @@ public class ReactInstanceSpecForTest {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
|
@ -5,9 +5,9 @@ package com.facebook.react;
|
|||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.JavaScriptExecutorFactory;
|
||||
import com.facebook.react.bridge.JSBundleLoader;
|
||||
import com.facebook.react.bridge.JSCJavaScriptExecutorFactory;
|
||||
import com.facebook.react.bridge.JavaScriptExecutorFactory;
|
||||
import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
|
||||
import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
|
||||
import com.facebook.react.common.LifecycleState;
|
||||
|
@ -125,6 +125,11 @@ public class ReactInstanceManagerBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ReactInstanceManagerBuilder addPackages(List<ReactPackage> reactPackages) {
|
||||
mPackages.addAll(reactPackages);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReactInstanceManagerBuilder setBridgeIdleDebugListener(
|
||||
NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener) {
|
||||
mBridgeIdleDebugListener = bridgeIdleDebugListener;
|
||||
|
|
Loading…
Reference in New Issue