From 87f1e22434210ad22f526422bbda0413f59786ce Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Tue, 18 Feb 2020 06:16:54 -0800 Subject: [PATCH] Deprecate console.disableYellowBox in favor of LogBox.ignoreAllLogs() Summary: We're replacing console.disableYellowBox (untyped, global hack, only warnings) with LogBox.ignoreAllLogs() (typed, local method, handles errors and warnings). Changelog: [General] [Removed] Replace console.disableYellowBox with LogBox.ignoreAllLogs. Reviewed By: TheSavior Differential Revision: D19813775 fbshipit-source-id: ffd33ddbca0276a27d23b5b6023a15aef761934e --- Libraries/LogBox/LogBox.js | 25 +++++++++++++++++++---- Libraries/LogBox/__tests__/LogBox-test.js | 19 +++++++++-------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Libraries/LogBox/LogBox.js b/Libraries/LogBox/LogBox.js index b231b9396ad..679a9dee45b 100644 --- a/Libraries/LogBox/LogBox.js +++ b/Libraries/LogBox/LogBox.js @@ -46,6 +46,10 @@ if (__DEV__) { LogBoxData.addIgnorePatterns(patterns); }, + ignoreAllLogs: (value?: ?boolean): void => { + LogBoxData.setDisabled(!!value); + }, + uninstall: (): void => { errorImpl = error; warnImpl = warn; @@ -64,18 +68,26 @@ if (__DEV__) { registerWarning(...args); }; - if ((console: any).disableLogBox === true) { + if ((console: any).disableYellowBox === true) { LogBoxData.setDisabled(true); + console.warn( + 'console.disableYellowBox has been deprecated and will be removed in a future release. Please use LogBox.ignoreAllLogs(value) instead.', + ); } - (Object.defineProperty: any)(console, 'disableLogBox', { + (Object.defineProperty: any)(console, 'disableYellowBox', { configurable: true, get: () => LogBoxData.isDisabled(), - set: value => LogBoxData.setDisabled(value), + set: value => { + LogBoxData.setDisabled(value); + console.warn( + 'console.disableYellowBox has been deprecated and will be removed in a future release. Please use LogBox.ignoreAllLogs(value) instead.', + ); + }, }); if (Platform.isTesting) { - (console: any).disableLogBox = true; + LogBoxData.setDisabled(true); } RCTLog.setWarningHandler((...args) => { @@ -171,6 +183,10 @@ if (__DEV__) { // Do nothing. }, + ignoreAllLogs: (value?: ?boolean): void => { + // Do nothing. + }, + install: (): void => { // Do nothing. }, @@ -185,6 +201,7 @@ module.exports = (LogBox: { // TODO: deprecated, replace with ignoreLogs ignoreWarnings($ReadOnlyArray): void, ignoreLogs($ReadOnlyArray): void, + ignoreAllLogs(?boolean): void, install(): void, uninstall(): void, ... diff --git a/Libraries/LogBox/__tests__/LogBox-test.js b/Libraries/LogBox/__tests__/LogBox-test.js index 2095de71bdf..974f1cca301 100644 --- a/Libraries/LogBox/__tests__/LogBox-test.js +++ b/Libraries/LogBox/__tests__/LogBox-test.js @@ -36,6 +36,7 @@ describe('LogBox', () => { jest.resetModules(); console.error = jest.fn(); console.warn = jest.fn(); + console.disableYellowBox = false; }); afterEach(() => { @@ -44,27 +45,27 @@ describe('LogBox', () => { console.warn = warn; }); - it('can set `disableLogBox` after installing', () => { - expect(console.disableLogBox).toBe(undefined); + it('can call `ignoreAllLogs` after installing', () => { + expect(LogBoxData.isDisabled()).toBe(false); LogBox.install(); - expect(console.disableLogBox).toBe(false); expect(LogBoxData.isDisabled()).toBe(false); - console.disableLogBox = true; + LogBox.ignoreAllLogs(true); - expect(console.disableLogBox).toBe(true); expect(LogBoxData.isDisabled()).toBe(true); }); - it('can set `disableLogBox` before installing', () => { - expect(console.disableLogBox).toBe(undefined); + it('can call `ignoreAllLogs` before installing', () => { + expect(LogBoxData.isDisabled()).toBe(false); + + LogBox.ignoreAllLogs(true); + + expect(LogBoxData.isDisabled()).toBe(true); - console.disableLogBox = true; LogBox.install(); - expect(console.disableLogBox).toBe(true); expect(LogBoxData.isDisabled()).toBe(true); });