import _ from 'lodash' import { observer } from 'mobx-react' import React, { ReactElement } from 'react' import FileNameOpener from '../lib/file-name-opener' import Err, { ParsedStackFileLine, ParsedStackMessageLine } from './err-model' const cypressLineRegex = /(cypress:\/\/|cypress_runner\.js)/ interface Props { err: Err } type StringOrElement = string | ReactElement const isMessageLine = (stackLine: ParsedStackFileLine | ParsedStackMessageLine) => { return (stackLine as ParsedStackMessageLine).message != null } const ErrorStack = observer(({ err }: Props) => { if (!err.parsedStack) return <>{err.stack}> // only display stack lines beyond the original message, since it's already // displayed above this in the UI let foundFirstStackLine = false const stackLines = _.filter(err.parsedStack, (line) => { if (foundFirstStackLine) return true if (isMessageLine(line)) return false foundFirstStackLine = true return true }) // instead of having every line indented, get rid of the smallest amount of // whitespace common to each line so the stack is aligned left but lines // with extra whitespace still have it const whitespaceLengths = _.map(stackLines, ({ whitespace }) => whitespace ? whitespace.length : 0) const commonWhitespaceLength = Math.min(...whitespaceLengths) const makeLine = (key: string, content: StringOrElement[]) => { return (