UNPKG

@tapjs/reporter

Version:

Pretty test output reporters for tap

89 lines 4.8 kB
import chalk from 'chalk'; import { Box, Text } from 'ink'; import React from 'react'; import { stringify } from 'tap-yaml'; import { same } from 'tcompare'; import { Diff } from './diff.js'; import { Source } from './source.js'; import { Stack } from './stack.js'; export const ResultDetails = ({ result, seen = [], heading, flush }) => { if (!result.diag || typeof result.diag !== 'object') return React.createElement(React.Fragment, null); const { test, stack, at, source, location, cause, error, errors, code, errorOrigin, message, ...otherDiags } = result.diag; if ('expected' in otherDiags && 'actual' in otherDiags && !('found' in otherDiags) && !('wanted' in otherDiags)) { otherDiags.found = otherDiags.actual; otherDiags.wanted = otherDiags.expected; delete otherDiags.actual; delete otherDiags.expected; } if ('found' in otherDiags && 'wanted' in otherDiags && !('diff' in otherDiags)) { const { diff } = same(otherDiags.found, otherDiags.wanted); otherDiags.diff = diff; } // if we have a diff, don't show found/wanted, as it is frequently huge. if (otherDiags.diff?.trimEnd()) { delete otherDiags.found; delete otherDiags.wanted; } const { diff } = otherDiags; delete otherDiags.diff; return (React.createElement(Box, { paddingLeft: !!heading ? 0 : 2, flexDirection: "column" }, heading ? React.createElement(Box, { flexDirection: "column", paddingTop: flush ? 0 : 1 }, React.createElement(Text, { color: "white", bold: true }, heading)) : React.createElement(React.Fragment, null), React.createElement(Source, { stack: stack, location: location, at: at, source: source, errorOrigin: errorOrigin }), React.createElement(Diff, { diff: diff }), error ? React.createElement(Text, null, stringify({ error }) .trimEnd() .replace(/^error:([^\n]*\n)?/, chalk.dim('error:$1'))) : React.createElement(React.Fragment, null), code ? React.createElement(Text, null, stringify({ code }) .trimEnd() .replace(/^code:([^\n]*\n)?/, chalk.dim('code:$1'))) : React.createElement(React.Fragment, null), !!Object.keys(otherDiags).length && (React.createElement(Text, { dimColor: true }, stringify(otherDiags).trimEnd())), React.createElement(Stack, { stack: stack }), cause !== undefined && (!!cause && typeof cause === 'object' ? /* c8 ignore start - exceedingly unlikely */ seen.includes(cause) ? '(circular)' : /* c8 ignore stop */ React.createElement(ResultDetails, { heading: `cause: ${typeof cause.message === 'string' ? `${typeof cause.type === 'string' ? cause.type : 'Error'}: ${cause.message}` : ''}`, flush: false, result: { ...result, diag: cause, }, seen: seen.concat(cause) }) : React.createElement(Box, { paddingTop: 1 }, React.createElement(Text, null, chalk.white.bold('cause: '), chalk.dim(stringify(cause).trimEnd())))), (errors !== undefined && Array.isArray(errors) && errors.length) ? [ React.createElement(Box, { flexDirection: "column", key: -1, paddingTop: 1 }, React.createElement(Text, { color: "white", bold: true }, "errors: [")), ...errors.map((e, i) => (React.createElement(Box, { key: i, flexDirection: "row", paddingLeft: 2, paddingTop: +!!i }, React.createElement(Text, { color: "white", bold: true }, `- `), !!e && typeof e === 'object' ? React.createElement(ResultDetails, { flush: true, result: { ...result, diag: e, }, heading: `${typeof e.message === 'string' ? `${typeof e.type === 'string' ? e.type : 'Error'}: ${e.message}` : ''}`, seen: seen.concat(e) }) : React.createElement(Text, { dimColor: true }, stringify(e).trimEnd())))), React.createElement(Box, { flexDirection: "column", key: errors.length }, React.createElement(Text, { color: "white", bold: true }, "]")), ] : React.createElement(React.Fragment, null))); }; //# sourceMappingURL=result-details.js.map