From 81c33b542d4d4966288fe7d265b2abcae717f683 Mon Sep 17 00:00:00 2001 From: Mehdi Mulani Date: Wed, 18 Jan 2017 12:24:53 -0800 Subject: [PATCH] Switch out DISABLE_YELLOW_BOX for IS_TESTING Summary: Switch to using IS_TESTING on the Platform module. While IS_TESTING has to be explicitly set in the test harness, this makes it more usable and stops people from relying on brittle variables in the (larger) environment. Reviewed By: fkgozali Differential Revision: D4423661 fbshipit-source-id: 27a80867778b9374bcba67b69f9c93d32c0a74b0 --- Libraries/ReactNative/YellowBox.js | 3 +-- Libraries/Utilities/Platform.ios.js | 4 ++++ React/Base/RCTPlatform.m | 6 ++++++ React/Modules/RCTProcessInfo.h | 15 --------------- React/Modules/RCTProcessInfo.m | 26 -------------------------- docs/Debugging.md | 2 +- 6 files changed, 12 insertions(+), 44 deletions(-) delete mode 100644 React/Modules/RCTProcessInfo.h delete mode 100644 React/Modules/RCTProcessInfo.m diff --git a/Libraries/ReactNative/YellowBox.js b/Libraries/ReactNative/YellowBox.js index a43e7a442..2c0852bab 100644 --- a/Libraries/ReactNative/YellowBox.js +++ b/Libraries/ReactNative/YellowBox.js @@ -70,8 +70,7 @@ if (__DEV__) { updateWarningMap.apply(null, arguments); }; - const ProcessInfo = require('NativeModules').ProcessInfo; - if (ProcessInfo && ProcessInfo.environment.DISABLE_YELLOW_BOX) { + if (Platform.isTesting) { (console: any).disableYellowBox = true; } } diff --git a/Libraries/Utilities/Platform.ios.js b/Libraries/Utilities/Platform.ios.js index b02cac772..9896c88c7 100644 --- a/Libraries/Utilities/Platform.ios.js +++ b/Libraries/Utilities/Platform.ios.js @@ -22,6 +22,10 @@ const Platform = { const constants = require('NativeModules').IOSConstants; return constants ? (constants.interfaceIdiom === 'tv') : false; }, + get isTesting(): boolean { + const constants = require('NativeModules').IOSConstants; + return constants && constants.isTesting; + }, select: (obj: Object) => obj.ios, }; diff --git a/React/Base/RCTPlatform.m b/React/Base/RCTPlatform.m index 61bc69977..766fd3874 100644 --- a/React/Base/RCTPlatform.m +++ b/React/Base/RCTPlatform.m @@ -30,6 +30,11 @@ static NSString *interfaceIdiom(UIUserInterfaceIdiom idiom) { } } +static BOOL isTestingEnvironment(void) { + NSDictionary *environment = [[NSProcessInfo processInfo] environment]; + return [environment[@"IS_TESTING"] boolValue]; +} + RCT_EXPORT_MODULE(IOSConstants) - (NSDictionary *)constantsToExport @@ -40,6 +45,7 @@ RCT_EXPORT_MODULE(IOSConstants) @"osVersion": [device systemVersion], @"systemName": [device systemName], @"interfaceIdiom": interfaceIdiom([device userInterfaceIdiom]), + @"isTesting": @(isTestingEnvironment()), }; } diff --git a/React/Modules/RCTProcessInfo.h b/React/Modules/RCTProcessInfo.h deleted file mode 100644 index f4a501fbe..000000000 --- a/React/Modules/RCTProcessInfo.h +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright (c) 2017-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import -#import - -@interface RCTProcessInfo : NSObject - -@end diff --git a/React/Modules/RCTProcessInfo.m b/React/Modules/RCTProcessInfo.m deleted file mode 100644 index bd15c2cf2..000000000 --- a/React/Modules/RCTProcessInfo.m +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2017-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import "RCTProcessInfo.h" - -@implementation RCTProcessInfo - -RCT_EXPORT_MODULE() - -- (NSDictionary *)constantsToExport -{ - NSProcessInfo *processInfo = [NSProcessInfo processInfo]; - return - @{ - @"environment": processInfo.environment, - @"arguments": processInfo.arguments, - }; -} - -@end diff --git a/docs/Debugging.md b/docs/Debugging.md index a011eb4ae..8817229cd 100644 --- a/docs/Debugging.md +++ b/docs/Debugging.md @@ -51,7 +51,7 @@ As with a RedBox, you can use `console.warn()` to trigger a YellowBox. YellowBoxes can be disabled during development by using `console.disableYellowBox = true;`. Specific warnings can be ignored programmatically by setting an array of prefixes that should be ignored: `console.ignoredYellowBox = ['Warning: ...'];`. -In CI/Xcode, YellowBoxes can also be disabled by setting the `DISABLE_YELLOW_BOX` environment variable. +In CI/Xcode, YellowBoxes can also be disabled by setting the `IS_TESTING` environment variable. > RedBoxes and YellowBoxes are automatically disabled in release (production) builds.