Skip to content

Commit

Permalink
Gate Platform.isTesting via __DEV__ on the native level (#38339)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
rshest authored and facebook-github-bot committed Jul 14, 2023
1 parent d9c8cd3 commit ecb58a1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
7 changes: 2 additions & 5 deletions packages/react-native/Libraries/Utilities/Platform.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions packages/react-native/Libraries/Utilities/Platform.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/CoreModules/RCTPlatform.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ - (dispatch_queue_t)methodQueue
.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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@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);
Expand Down Expand Up @@ -74,7 +75,8 @@ private String uiMode() {
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;
Expand Down

0 comments on commit ecb58a1

Please sign in to comment.