react-native-macos/Libraries/LogBox/UI/__tests__/LogBoxInspectorFooter-test.js

67 строки
1.5 KiB
JavaScript
Исходник Обычный вид История

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/
'use strict';
const render = require('../../../../jest/renderer');
const LogBoxInspectorFooter = require('../LogBoxInspectorFooter').default;
const React = require('react');
describe('LogBoxInspectorFooter', () => {
it('should render two buttons for warning', () => {
const output = render.shallowRender(
<LogBoxInspectorFooter
onMinimize={() => {}}
onDismiss={() => {}}
level="warn"
/>,
);
expect(output).toMatchSnapshot();
});
it('should render two buttons for error', () => {
const output = render.shallowRender(
<LogBoxInspectorFooter
onMinimize={() => {}}
onDismiss={() => {}}
level="error"
/>,
);
expect(output).toMatchSnapshot();
});
it('should render two buttons for fatal', () => {
const output = render.shallowRender(
<LogBoxInspectorFooter
onMinimize={() => {}}
onDismiss={() => {}}
level="fatal"
LogBox - Add syntax error handling Summary: This diff adds handling for syntax errors. ## Strategy To do this we introduce a new log level type syntax, giving us these levels with semantics: - `warn` - console warns, show collapsed, dismissible - `error` - console errors, show collapsed, dismissible - `fatal` - thrown exceptions, show expanded, not dismissible - `syntax` - thrown exceptions for invalid syntax, show expanded, not dismissible Syntax errors shows expanded, covers all other errors, and are only dismissible when the syntax error is fixed and updated with Fast Refresh. Once the syntax error is fixed, it reveals any previously covered fatals, errors, or warnings behind it In many ways, this makes syntax errors the highest level error. ## Visuals Syntax errors also have their own display formatting. Stack traces for syntax errors don't make sense, so we don't show them. Instead, we show the syntax error message and a code frame for the error. The code frame is also updated so that is doesn't wrap and is horizontally scrollable, making it easier to read. ## Detecting syntax errors To detect syntax errors we've updated `LogBoxData.addException` to call the parse function `parseLogBoxException`. This method will perform a regex on the error message to detect: - file name - location - error message - codeframe If this regex fails for any reason to find all four parts, we'll fall back to a fatal. Over time we'll update this regex to be more robust and handle more cases we've missed. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D18278862 fbshipit-source-id: 59069aba38a27c44787e5248b2973c3a345c4a0a
2019-11-02 02:05:02 +03:00
/>,
);
expect(output).toMatchSnapshot();
});
it('should render no buttons and a message for syntax error', () => {
LogBox - Add syntax error handling Summary: This diff adds handling for syntax errors. ## Strategy To do this we introduce a new log level type syntax, giving us these levels with semantics: - `warn` - console warns, show collapsed, dismissible - `error` - console errors, show collapsed, dismissible - `fatal` - thrown exceptions, show expanded, not dismissible - `syntax` - thrown exceptions for invalid syntax, show expanded, not dismissible Syntax errors shows expanded, covers all other errors, and are only dismissible when the syntax error is fixed and updated with Fast Refresh. Once the syntax error is fixed, it reveals any previously covered fatals, errors, or warnings behind it In many ways, this makes syntax errors the highest level error. ## Visuals Syntax errors also have their own display formatting. Stack traces for syntax errors don't make sense, so we don't show them. Instead, we show the syntax error message and a code frame for the error. The code frame is also updated so that is doesn't wrap and is horizontally scrollable, making it easier to read. ## Detecting syntax errors To detect syntax errors we've updated `LogBoxData.addException` to call the parse function `parseLogBoxException`. This method will perform a regex on the error message to detect: - file name - location - error message - codeframe If this regex fails for any reason to find all four parts, we'll fall back to a fatal. Over time we'll update this regex to be more robust and handle more cases we've missed. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D18278862 fbshipit-source-id: 59069aba38a27c44787e5248b2973c3a345c4a0a
2019-11-02 02:05:02 +03:00
const output = render.shallowRender(
<LogBoxInspectorFooter
onMinimize={() => {}}
onDismiss={() => {}}
level="syntax"
/>,
);
expect(output).toMatchSnapshot();
});
});