Skip to content

Commit

Permalink
Deprecate console.disableYellowBox in favor of LogBox.ignoreAllLogs()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rickhanlonii authored and facebook-github-bot committed Feb 18, 2020
1 parent 799bf56 commit 87f1e22
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
25 changes: 21 additions & 4 deletions Libraries/LogBox/LogBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ if (__DEV__) {
LogBoxData.addIgnorePatterns(patterns);
},

ignoreAllLogs: (value?: ?boolean): void => {
LogBoxData.setDisabled(!!value);
},

uninstall: (): void => {
errorImpl = error;
warnImpl = warn;
Expand All @@ -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) => {
Expand Down Expand Up @@ -171,6 +183,10 @@ if (__DEV__) {
// Do nothing.
},

ignoreAllLogs: (value?: ?boolean): void => {
// Do nothing.
},

install: (): void => {
// Do nothing.
},
Expand All @@ -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,
...
Expand Down
19 changes: 10 additions & 9 deletions Libraries/LogBox/__tests__/LogBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('LogBox', () => {
jest.resetModules();
console.error = jest.fn();
console.warn = jest.fn();
console.disableYellowBox = false;
});

afterEach(() => {
Expand All @@ -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);
});

Expand Down

0 comments on commit 87f1e22

Please sign in to comment.