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
This commit is contained in:
Rick Hanlon
2020-02-18 06:19:45 -08:00
committed by Facebook Github Bot
parent 799bf56f6f
commit 87f1e22434
2 changed files with 31 additions and 13 deletions
+21 -4
View File
@@ -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<IgnorePattern>): void,
ignoreLogs($ReadOnlyArray<IgnorePattern>): void,
ignoreAllLogs(?boolean): void,
install(): void,
uninstall(): void,
...
+10 -9
View File
@@ -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);
});