Gate Platform.isTesting via __DEV__ on the native level (#38339)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38339

## Changelog:
[Internal] -

In D13050583, the `Platform.isTesting` was unconditionally forced to `false` in `__DEV__` on JS side.

On some platforms, we may want to run tests in the release mode.

This hoists these gatings down to the corresponding platforms' native modules.

Reviewed By: ryancat

Differential Revision: D47438069

fbshipit-source-id: 5bae3df9873f659f65179df93e727108d0062047
This commit is contained in:
Ruslan Shestopalyuk
2023-07-13 18:15:37 -07:00
committed by Facebook GitHub Bot
parent d9c8cd3b40
commit ecb58a1d85
4 changed files with 8 additions and 12 deletions
@@ -54,11 +54,8 @@ const Platform = {
},
// $FlowFixMe[unsafe-getters-setters]
get isTesting(): boolean {
if (__DEV__) {
// $FlowFixMe[object-this-reference]
return this.constants.isTesting;
}
return false;
// $FlowFixMe[object-this-reference]
return this.constants.isTesting;
},
// $FlowFixMe[unsafe-getters-setters]
get isTV(): boolean {
@@ -59,11 +59,8 @@ const Platform = {
},
// $FlowFixMe[unsafe-getters-setters]
get isTesting(): boolean {
if (__DEV__) {
// $FlowFixMe[object-this-reference]
return this.constants.isTesting;
}
return false;
// $FlowFixMe[object-this-reference]
return this.constants.isTesting;
},
select: <T>(spec: PlatformSelectSpec<T>): T =>
// $FlowFixMe[incompatible-return]
@@ -69,7 +69,7 @@ RCT_EXPORT_MODULE(PlatformConstants)
.osVersion = [device systemVersion],
.systemName = [device systemName],
.interfaceIdiom = interfaceIdiom([device userInterfaceIdiom]),
.isTesting = RCTRunningInTestEnvironment() ? true : false,
.isTesting = (RCT_DEV && RCTRunningInTestEnvironment()) ? true : false,
.reactNativeVersion = JS::NativePlatformConstantsIOS::ConstantsReactNativeVersion::Builder(
{.minor = [versions[@"minor"] doubleValue],
.major = [versions[@"major"] doubleValue],
@@ -28,6 +28,7 @@ import java.util.Map;
@SuppressLint("HardwareIds")
public class AndroidInfoModule extends NativePlatformConstantsAndroidSpec implements TurboModule {
private static final String IS_TESTING = "IS_TESTING";
private static final boolean DEV = ReactBuildConfig.DEBUG;
public AndroidInfoModule(ReactApplicationContext reactContext) {
super(reactContext);
@@ -74,7 +75,8 @@ public class AndroidInfoModule extends NativePlatformConstantsAndroidSpec implem
AndroidInfoHelpers.getServerHost(getReactApplicationContext().getApplicationContext()));
}
constants.put(
"isTesting", "true".equals(System.getProperty(IS_TESTING)) || isRunningScreenshotTest());
"isTesting",
DEV && ("true".equals(System.getProperty(IS_TESTING)) || isRunningScreenshotTest()));
constants.put("reactNativeVersion", ReactNativeVersion.VERSION);
constants.put("uiMode", uiMode());
return constants;