Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/react-native/Libraries/LogBox/LogBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ if (__DEV__) {
let format = args[0];
if (typeof format === 'string') {
const filterResult =
require('../LogBox/Data/LogBoxData').checkWarningFilter(
// For legacy reasons, we strip the warning prefix from the message.
// Can remove this once we remove the warning module altogether.
format.replace(/^Warning: /, ''),
);
require('../LogBox/Data/LogBoxData').checkWarningFilter(format);
if (filterResult.monitorEvent !== 'warning_unhandled') {
if (filterResult.suppressCompletely) {
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/LogBox/UI/LogBoxMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function TappableLinks(props: {
}

const cleanContent = (content: string) =>
content.replace(/^(TransformError |Warning: (Warning: )?|Error: )/g, '');
content.replace(/^(TransformError |Error: )/g, '');

function LogBoxMessage(props: Props): React.Node {
const {content, substitutions}: Message = props.message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,34 +179,6 @@ describe('LogBoxMessage', () => {
expect(output).toMatchSnapshot();
});

it('Should strip "Warning: " without breaking substitution', async () => {
const output = await render.create(
<LogBoxMessage
style={{}}
message={{
content: 'Warning: normal substitution normal',
substitutions: [{length: 12, offset: 16}],
}}
/>,
);

expect(output).toMatchSnapshot();
});

it('Should strip "Warning: Warning: " without breaking substitution', async () => {
const output = await render.create(
<LogBoxMessage
style={{}}
message={{
content: 'Warning: Warning: normal substitution normal',
substitutions: [{length: 12, offset: 25}],
}}
/>,
);

expect(output).toMatchSnapshot();
});

it('Should make links tappable', async () => {
const output = await render.create(
<LogBoxMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,6 @@ Array [
]
`;

exports[`LogBoxMessage Should strip "Warning: " without breaking substitution 1`] = `
Array [
<Text>
normal
</Text>,
<Text
style={Object {}}
>
substitution
</Text>,
<Text>
normal
</Text>,
]
`;

exports[`LogBoxMessage Should strip "Warning: Warning: " without breaking substitution 1`] = `
Array [
<Text>
normal
</Text>,
<Text
style={Object {}}
>
substitution
</Text>,
<Text>
normal
</Text>,
]
`;

exports[`LogBoxMessage should render a plaintext message and clean the content 1`] = `
<Text>
This should not start with Error:
Expand Down
128 changes: 1 addition & 127 deletions packages/react-native/Libraries/LogBox/__tests__/LogBox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ declare var console: any;

function mockFilterResult(returnValues: $FlowFixMe) {
(LogBoxData.checkWarningFilter: any).mockReturnValue({
finalFormat: 'Warning: ...',
finalFormat: '...',
forceDialogImmediately: false,
suppressDialog_LEGACY: false,
suppressCompletely: false,
Expand Down Expand Up @@ -126,17 +126,6 @@ describe('LogBox', () => {
expect(LogBoxData.reportLogBoxError).toBeCalledWith(mockError);
});

it('only registers errors beginning with "Warning: "', () => {
jest.spyOn(LogBoxData, 'addLog');
jest.spyOn(LogBoxData, 'checkWarningFilter');

LogBox.install();

console.error('...');
expect(LogBoxData.addLog).not.toBeCalled();
expect(LogBoxData.checkWarningFilter).not.toBeCalled();
});

it('registers react errors with the formatting from filter', () => {
jest.spyOn(LogBoxData, 'addLog');
jest.spyOn(LogBoxData, 'checkWarningFilter');
Expand Down Expand Up @@ -245,121 +234,6 @@ describe('LogBox', () => {
);
});

it('registers warning module errors with the formatting from filter', () => {
jest.spyOn(LogBoxData, 'addLog');
jest.spyOn(LogBoxData, 'checkWarningFilter');

mockFilterResult({
finalFormat: 'Custom format',
});

ExceptionsManager.installConsoleErrorReporter();
LogBox.install();

console.error('Warning: ...');
expect(LogBoxData.addLog).toBeCalledWith(
expect.objectContaining({
message: {content: 'Custom format', substitutions: []},
category: 'Custom format',
}),
);
expect(LogBoxData.checkWarningFilter).toBeCalledWith('...');
});

it('registers warning module errors as errors by default', () => {
jest.spyOn(LogBoxData, 'addLog');
jest.spyOn(LogBoxData, 'checkWarningFilter');

mockFilterResult({});

ExceptionsManager.installConsoleErrorReporter();
LogBox.install();

console.error('Warning: ...');
expect(LogBoxData.addLog).toBeCalledWith(
expect.objectContaining({level: 'error'}),
);
expect(LogBoxData.checkWarningFilter).toBeCalledWith('...');
});

it('registers warning module errors with only legacy suppression as warning', () => {
jest.spyOn(LogBoxData, 'addLog');
jest.spyOn(LogBoxData, 'checkWarningFilter');

mockFilterResult({
suppressDialog_LEGACY: true,
monitorEvent: 'warning',
});

ExceptionsManager.installConsoleErrorReporter();
LogBox.install();

console.error('Warning: ...');
expect(LogBoxData.addLog).toBeCalledWith(
expect.objectContaining({level: 'warn'}),
);
});

it('registers warning module errors with a forced dialog as fatals', () => {
jest.spyOn(LogBoxData, 'addLog');
jest.spyOn(LogBoxData, 'checkWarningFilter');

mockFilterResult({
forceDialogImmediately: true,
monitorEvent: 'warning',
});

ExceptionsManager.installConsoleErrorReporter();
LogBox.install();

console.error('Warning: ...');
expect(LogBoxData.addLog).toBeCalledWith(
expect.objectContaining({level: 'fatal'}),
);
});

it('ignores warning module errors that are suppressed completely', () => {
jest.spyOn(LogBoxData, 'addLog');
jest.spyOn(LogBoxData, 'checkWarningFilter');

mockFilterResult({
suppressCompletely: true,
monitorEvent: 'warning',
});

ExceptionsManager.installConsoleErrorReporter();
LogBox.install();

console.error('Warning: ...');
expect(LogBoxData.addLog).not.toBeCalled();
});

it('ignores warning module errors that are pattern ignored', () => {
jest.spyOn(LogBoxData, 'checkWarningFilter');
jest.spyOn(LogBoxData, 'isMessageIgnored').mockReturnValue(true);
jest.spyOn(LogBoxData, 'addLog');

mockFilterResult({});

LogBox.install();

console.error('Warning: ...');
expect(LogBoxData.addLog).not.toBeCalled();
});

it('ignores warning module errors that are from LogBox itself', () => {
jest.spyOn(LogBoxData, 'checkWarningFilter');
jest.spyOn(LogBoxData, 'isLogBoxErrorMessage').mockReturnValue(true);
jest.spyOn(LogBoxData, 'addLog');

mockFilterResult({});

LogBox.install();

console.error('Warning: ...');
expect(LogBoxData.addLog).not.toBeCalled();
});

it('ignores logs that are pattern ignored"', () => {
jest.spyOn(LogBoxData, 'checkWarningFilter');
jest.spyOn(LogBoxData, 'isMessageIgnored').mockReturnValue(true);
Expand Down
Loading