mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
7ad862eaba
Summary: This diff adds the ability to press the file name of a code frame to open the file in your editor. Note: I re-worked the frame location to extract the frame row and column at parse time so that we don't need to do any clowny regexes down stream. Changelog: [Internal] Reviewed By: cpojer Differential Revision: D18358283 fbshipit-source-id: 705e07d229c66ecfd225a8fb65ef2f78b5034c9c
380 lines
9.1 KiB
JavaScript
380 lines
9.1 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.
|
|
*
|
|
* @format
|
|
* @emails oncall+react_native
|
|
* @flow
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const React = require('react');
|
|
const LogBoxContainer = require('../LogBoxContainer').default;
|
|
const LogBoxLog = require('../../Data/LogBoxLog').default;
|
|
const render = require('../../../../jest/renderer');
|
|
|
|
describe('LogBoxContainer', () => {
|
|
it('should render null with no logs', () => {
|
|
const output = render.shallowRender(
|
|
<LogBoxContainer
|
|
onDismiss={() => {}}
|
|
onDismissWarns={() => {}}
|
|
onDismissErrors={() => {}}
|
|
logs={new Set()}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render the latest warning', () => {
|
|
const output = render.shallowRender(
|
|
<LogBoxContainer
|
|
onDismiss={() => {}}
|
|
onDismissWarns={() => {}}
|
|
onDismissErrors={() => {}}
|
|
logs={
|
|
new Set([
|
|
new LogBoxLog(
|
|
'warn',
|
|
{
|
|
content: 'Some kind of message',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message',
|
|
[],
|
|
),
|
|
new LogBoxLog(
|
|
'warn',
|
|
{
|
|
content: 'Some kind of message (latest)',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message (latest)',
|
|
[],
|
|
),
|
|
])
|
|
}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render the latest error', () => {
|
|
const output = render.shallowRender(
|
|
<LogBoxContainer
|
|
onDismiss={() => {}}
|
|
onDismissWarns={() => {}}
|
|
onDismissErrors={() => {}}
|
|
logs={
|
|
new Set([
|
|
new LogBoxLog(
|
|
'error',
|
|
{
|
|
content: 'Some kind of message',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message',
|
|
[],
|
|
),
|
|
new LogBoxLog(
|
|
'error',
|
|
{
|
|
content: 'Some kind of message (latest)',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message (latest)',
|
|
[],
|
|
),
|
|
])
|
|
}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render both an error and warning', () => {
|
|
const output = render.shallowRender(
|
|
<LogBoxContainer
|
|
onDismiss={() => {}}
|
|
onDismissWarns={() => {}}
|
|
onDismissErrors={() => {}}
|
|
logs={
|
|
new Set([
|
|
new LogBoxLog(
|
|
'warn',
|
|
{
|
|
content: 'Some kind of message',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message',
|
|
[],
|
|
),
|
|
new LogBoxLog(
|
|
'error',
|
|
{
|
|
content: 'Some kind of message (latest)',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message (latest)',
|
|
[],
|
|
),
|
|
])
|
|
}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render null when disabled with non-fatal error and warning', () => {
|
|
const output = render.shallowRender(
|
|
<LogBoxContainer
|
|
isDisabled
|
|
onDismiss={() => {}}
|
|
onDismissWarns={() => {}}
|
|
onDismissErrors={() => {}}
|
|
logs={
|
|
new Set([
|
|
new LogBoxLog(
|
|
'warn',
|
|
{
|
|
content: 'Some kind of message',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message',
|
|
[],
|
|
),
|
|
new LogBoxLog(
|
|
'error',
|
|
{
|
|
content: 'Some kind of message (latest)',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message (latest)',
|
|
[],
|
|
),
|
|
])
|
|
}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render fatal before warn and error', () => {
|
|
const output = render.shallowRender(
|
|
<LogBoxContainer
|
|
onDismiss={() => {}}
|
|
onDismissWarns={() => {}}
|
|
onDismissErrors={() => {}}
|
|
logs={
|
|
new Set([
|
|
new LogBoxLog(
|
|
'fatal',
|
|
{
|
|
content: 'Some kind of fatal message',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of fatal message',
|
|
[],
|
|
),
|
|
new LogBoxLog(
|
|
'warn',
|
|
{
|
|
content: 'Some kind of message',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message',
|
|
[],
|
|
),
|
|
new LogBoxLog(
|
|
'error',
|
|
{
|
|
content: 'Some kind of message (latest)',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message (latest)',
|
|
[],
|
|
),
|
|
])
|
|
}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render most recent fatal', () => {
|
|
const output = render.shallowRender(
|
|
<LogBoxContainer
|
|
onDismiss={() => {}}
|
|
onDismissWarns={() => {}}
|
|
onDismissErrors={() => {}}
|
|
logs={
|
|
new Set([
|
|
new LogBoxLog(
|
|
'fatal',
|
|
{
|
|
content: 'Should not be selected',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of fatal message',
|
|
[],
|
|
),
|
|
new LogBoxLog(
|
|
'fatal',
|
|
{
|
|
content: 'Should be selected',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message',
|
|
[],
|
|
),
|
|
])
|
|
}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render fatal error even when disabled', () => {
|
|
const output = render.shallowRender(
|
|
<LogBoxContainer
|
|
isDisabled
|
|
onDismiss={() => {}}
|
|
onDismissWarns={() => {}}
|
|
onDismissErrors={() => {}}
|
|
logs={
|
|
new Set([
|
|
new LogBoxLog(
|
|
'fatal',
|
|
{
|
|
content: 'Should be selected',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of message',
|
|
[],
|
|
),
|
|
])
|
|
}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render most recent syntax error', () => {
|
|
const output = render.shallowRender(
|
|
<LogBoxContainer
|
|
onDismiss={() => {}}
|
|
onDismissWarns={() => {}}
|
|
onDismissErrors={() => {}}
|
|
logs={
|
|
new Set([
|
|
new LogBoxLog(
|
|
'syntax',
|
|
{
|
|
content: 'Should not be selected',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of syntax error message',
|
|
[],
|
|
{
|
|
fileName:
|
|
'/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js',
|
|
location: {row: 199, column: 0},
|
|
content: ` 197 | });
|
|
198 |
|
|
> 199 | export default CrashReactApp;
|
|
| ^
|
|
200 |`,
|
|
},
|
|
),
|
|
new LogBoxLog(
|
|
'syntax',
|
|
{
|
|
content: 'Should be selected',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of syntax error message',
|
|
[],
|
|
{
|
|
fileName:
|
|
'/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js',
|
|
location: {row: 199, column: 0},
|
|
content: ` 197 | });
|
|
198 |
|
|
> 199 | export default CrashReactApp;
|
|
| ^
|
|
200 |`,
|
|
},
|
|
),
|
|
])
|
|
}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render syntax error even when disabled', () => {
|
|
const output = render.shallowRender(
|
|
<LogBoxContainer
|
|
isDisabled
|
|
onDismiss={() => {}}
|
|
onDismissWarns={() => {}}
|
|
onDismissErrors={() => {}}
|
|
logs={
|
|
new Set([
|
|
new LogBoxLog(
|
|
'syntax',
|
|
{
|
|
content: 'Should be selected',
|
|
substitutions: [],
|
|
},
|
|
[],
|
|
'Some kind of syntax error message',
|
|
[],
|
|
{
|
|
fileName:
|
|
'/path/to/RKJSModules/Apps/CrashReact/CrashReactApp.js',
|
|
location: {row: 199, column: 0},
|
|
content: ` 197 | });
|
|
198 |
|
|
> 199 | export default CrashReactApp;
|
|
| ^
|
|
200 |`,
|
|
},
|
|
),
|
|
])
|
|
}
|
|
/>,
|
|
);
|
|
|
|
expect(output).toMatchSnapshot();
|
|
});
|
|
});
|