yhtml5-test
Version:
A test framework for front-end projects
113 lines (92 loc) • 4.42 kB
JavaScript
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React, { Component } from 'react';
import StackFrame from './StackFrame';
import Collapsible from '../components/Collapsible';
import { isInternalFile } from '../utils/isInternalFile';
import { isBultinErrorName } from '../utils/isBultinErrorName';
var traceStyle = {
fontSize: '1em',
flex: '0 1 auto',
minHeight: '0px',
overflow: 'auto'
};
var StackTrace = function (_Component) {
_inherits(StackTrace, _Component);
function StackTrace() {
_classCallCheck(this, StackTrace);
return _possibleConstructorReturn(this, (StackTrace.__proto__ || Object.getPrototypeOf(StackTrace)).apply(this, arguments));
}
_createClass(StackTrace, [{
key: 'renderFrames',
value: function renderFrames() {
var _props = this.props,
stackFrames = _props.stackFrames,
errorName = _props.errorName,
contextSize = _props.contextSize,
launchEditorEndpoint = _props.launchEditorEndpoint;
var renderedFrames = [];
var hasReachedAppCode = false,
currentBundle = [],
bundleCount = 0;
stackFrames.forEach(function (frame, index) {
var fileName = frame.fileName,
sourceFileName = frame._originalFileName;
var isInternalUrl = isInternalFile(sourceFileName, fileName);
var isThrownIntentionally = !isBultinErrorName(errorName);
var shouldCollapse = isInternalUrl && (isThrownIntentionally || hasReachedAppCode);
if (!isInternalUrl) {
hasReachedAppCode = true;
}
var frameEle = React.createElement(StackFrame, {
key: 'frame-' + index,
frame: frame,
contextSize: contextSize,
critical: index === 0,
showCode: !shouldCollapse,
launchEditorEndpoint: launchEditorEndpoint
});
var lastElement = index === stackFrames.length - 1;
if (shouldCollapse) {
currentBundle.push(frameEle);
}
if (!shouldCollapse || lastElement) {
if (currentBundle.length === 1) {
renderedFrames.push(currentBundle[0]);
} else if (currentBundle.length > 1) {
bundleCount++;
renderedFrames.push(React.createElement(
Collapsible,
{ key: 'bundle-' + bundleCount },
currentBundle
));
}
currentBundle = [];
}
if (!shouldCollapse) {
renderedFrames.push(frameEle);
}
});
return renderedFrames;
}
}, {
key: 'render',
value: function render() {
return React.createElement(
'div',
{ style: traceStyle },
this.renderFrames()
);
}
}]);
return StackTrace;
}(Component);
export default StackTrace;