mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
1801dbd333
Summary: In YellowBox we were parsing the component stack trace in a narrow set of use cases, which are commonly missed (I see this working ~50% of the time). That seems to be overly cautious. In LogBox, since there's a nice UI for component stack traces, let's be more aggressive about finding the component stack and we can address it with feedback if we find that there are real issues with this strategy in practice Changelog: [Internal] Reviewed By: cpojer Differential Revision: D18053389 fbshipit-source-id: 48f116e2bd3f8cc43d53d3668fd6d5b8d7cba2a4
165 lines
3.9 KiB
JavaScript
165 lines
3.9 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @emails oncall+react_native
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
jest.mock('../../../Core/Devtools/parseErrorStack', () => {
|
|
return {__esModule: true, default: jest.fn(() => [])};
|
|
});
|
|
|
|
const LogBoxLogParser = require('../LogBoxLogParser').default;
|
|
|
|
describe('LogBoxLogParser', () => {
|
|
it('parses strings', () => {
|
|
expect(LogBoxLogParser({args: ['A']})).toEqual({
|
|
componentStack: [],
|
|
stack: [],
|
|
category: 'A',
|
|
message: {
|
|
content: 'A',
|
|
substitutions: [],
|
|
},
|
|
});
|
|
});
|
|
|
|
it('parses strings with arguments', () => {
|
|
expect(LogBoxLogParser({args: ['A', 'B', 'C']})).toEqual({
|
|
componentStack: [],
|
|
stack: [],
|
|
category: 'A B C',
|
|
message: {
|
|
content: 'A B C',
|
|
substitutions: [],
|
|
},
|
|
});
|
|
});
|
|
|
|
it('parses formatted strings', () => {
|
|
expect(LogBoxLogParser({args: ['%s', 'A']})).toEqual({
|
|
componentStack: [],
|
|
stack: [],
|
|
category: '\ufeff%s',
|
|
message: {
|
|
content: 'A',
|
|
substitutions: [
|
|
{
|
|
length: 1,
|
|
offset: 0,
|
|
},
|
|
],
|
|
},
|
|
});
|
|
});
|
|
|
|
it('parses formatted strings with insufficient arguments', () => {
|
|
expect(LogBoxLogParser({args: ['%s %s', 'A']})).toEqual({
|
|
componentStack: [],
|
|
stack: [],
|
|
category: '\ufeff%s %s',
|
|
message: {
|
|
content: 'A %s',
|
|
substitutions: [
|
|
{
|
|
length: 1,
|
|
offset: 0,
|
|
},
|
|
{
|
|
length: 2,
|
|
offset: 2,
|
|
},
|
|
],
|
|
},
|
|
});
|
|
});
|
|
|
|
it('parses formatted strings with excess arguments', () => {
|
|
expect(LogBoxLogParser({args: ['%s', 'A', 'B']})).toEqual({
|
|
componentStack: [],
|
|
stack: [],
|
|
category: '\ufeff%s B',
|
|
message: {
|
|
content: 'A B',
|
|
substitutions: [
|
|
{
|
|
length: 1,
|
|
offset: 0,
|
|
},
|
|
],
|
|
},
|
|
});
|
|
});
|
|
|
|
it('treats "%s" in arguments as literals', () => {
|
|
expect(LogBoxLogParser({args: ['%s', '%s', 'A']})).toEqual({
|
|
componentStack: [],
|
|
stack: [],
|
|
category: '\ufeff%s A',
|
|
message: {
|
|
content: '%s A',
|
|
substitutions: [
|
|
{
|
|
length: 2,
|
|
offset: 0,
|
|
},
|
|
],
|
|
},
|
|
});
|
|
});
|
|
|
|
it('detects a component stack in the second argument', () => {
|
|
expect(
|
|
LogBoxLogParser({
|
|
args: [
|
|
'Some kind of message',
|
|
'\n in MyComponent (at filename.js:1)\n in MyOtherComponent (at filename2.js:1)',
|
|
],
|
|
}),
|
|
).toEqual({
|
|
componentStack: [
|
|
{component: 'MyComponent', location: 'filename.js:1'},
|
|
{component: 'MyOtherComponent', location: 'filename2.js:1'},
|
|
],
|
|
stack: [],
|
|
category: 'Some kind of message',
|
|
message: {
|
|
content: 'Some kind of message',
|
|
substitutions: [],
|
|
},
|
|
});
|
|
});
|
|
|
|
it('detects a component stack in the nth argument', () => {
|
|
expect(
|
|
LogBoxLogParser({
|
|
args: [
|
|
'Some kind of message',
|
|
'Some other kind of message',
|
|
'\n in MyComponent (at filename.js:1)\n in MyOtherComponent (at filename2.js:1)',
|
|
'Some third kind of message',
|
|
],
|
|
}),
|
|
).toEqual({
|
|
componentStack: [
|
|
{component: 'MyComponent', location: 'filename.js:1'},
|
|
{component: 'MyOtherComponent', location: 'filename2.js:1'},
|
|
],
|
|
stack: [],
|
|
category:
|
|
'Some kind of message Some other kind of message Some third kind of message',
|
|
message: {
|
|
content:
|
|
'Some kind of message Some other kind of message Some third kind of message',
|
|
substitutions: [],
|
|
},
|
|
});
|
|
});
|
|
});
|