Set Platform.isTesting true when running Server Snapshot Tests

Summary:
`Platform.isTesting` returns false when running SSTs. This diff changes that to true.

See https://our.intern.facebook.com/intern/qa/9690/how-to-detect-when-running-as-sst for inspiration.

I fixed this for iOS in D13981728.

Reviewed By: cpojer

Differential Revision: D14244606

fbshipit-source-id: ed95b772cc4206cf7c835aed7415aa5fc5fbdf7d
This commit is contained in:
Peter Argany
2019-02-28 12:42:13 -08:00
committed by Facebook Github Bot
parent 0ae48f5c38
commit f2d20d2904

View File

@@ -76,7 +76,8 @@ public class AndroidInfoModule extends ReactContextBaseJavaModule {
if (ReactBuildConfig.DEBUG) {
constants.put("ServerHost", AndroidInfoHelpers.getServerHost());
}
constants.put("isTesting", "true".equals(System.getProperty(IS_TESTING)));
constants.put("isTesting", "true".equals(System.getProperty(IS_TESTING))
|| isRunningScreenshotTest());
constants.put("reactNativeVersion", ReactNativeVersion.VERSION);
constants.put("uiMode", uiMode());
return constants;
@@ -86,4 +87,13 @@ public class AndroidInfoModule extends ReactContextBaseJavaModule {
public String getAndroidID(){
return Secure.getString(getReactApplicationContext().getContentResolver(),Secure.ANDROID_ID);
}
private Boolean isRunningScreenshotTest() {
try {
Class.forName("android.support.test.rule.ActivityTestRule");
return true;
} catch (ClassNotFoundException ignored) {
return false;
}
}
}