Use native as the source of truth to decide if a test should use Fabric
Reviewed By: fkgozali Differential Revision: D7304221 fbshipit-source-id: cdd7053e6ce6522474df261db5710e2d9c013be6
This commit is contained in:
parent
0d924dd629
commit
785c8f7eb9
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @providesModule TestFabricView
|
||||
* @flow
|
||||
* @format
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* This is a switch on the correct View to use for Fabric testing purposes
|
||||
*/
|
||||
let TestFabricView;
|
||||
const FabricTestModule = require('NativeModules').FabricTestModule;
|
||||
if (FabricTestModule && FabricTestModule.IS_FABRIC_ENABLED) {
|
||||
TestFabricView = require('FabricView');
|
||||
} else {
|
||||
TestFabricView = require('View');
|
||||
}
|
||||
|
||||
module.exports = TestFabricView;
|
|
@ -12,6 +12,7 @@ import android.test.ActivityInstrumentationTestCase2;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.testing.fabric.FabricTestModule;
|
||||
import com.facebook.react.testing.idledetection.IdleWaiter;
|
||||
|
||||
/**
|
||||
|
@ -110,7 +111,11 @@ public abstract class ReactInstrumentationTest extends
|
|||
* Override this method to provide extra native modules to be loaded before the app starts
|
||||
*/
|
||||
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() {
|
||||
return new ReactInstanceSpecForTest();
|
||||
ReactInstanceSpecForTest instanceSpec = new ReactInstanceSpecForTest();
|
||||
if (isFabricTest()) {
|
||||
instanceSpec.addNativeModule(new FabricTestModule(isFabricTest()));
|
||||
}
|
||||
return instanceSpec;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* 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.fabric;
|
||||
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
|
||||
/**
|
||||
* Module to indicate if a test is using Fabric
|
||||
*/
|
||||
public final class FabricTestModule extends BaseJavaModule {
|
||||
|
||||
private final boolean mIsFabricEnabled;
|
||||
|
||||
public FabricTestModule(boolean isFabricEnabled) {
|
||||
mIsFabricEnabled = isFabricEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "FabricTestModule";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getConstants() {
|
||||
return MapBuilder.<String, Object>of("IS_FABRIC_ENABLED", mIsFabricEnabled);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue