-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
result-details.tsx
84 lines (79 loc) · 2 KB
/
result-details.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import chalk from 'chalk'
import { Box, Text } from 'ink'
import React, { FC } from 'react'
import { Result } from 'tap-parser'
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: FC<{ result: Result }> = ({ result }) => {
if (!result.diag || typeof result.diag !== 'object') return <></>
const {
test,
stack,
at,
source,
location,
errorOrigin,
error,
code,
...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 (
<Box paddingLeft={4} flexDirection="column">
<Source
stack={stack}
location={location}
at={at}
source={source}
errorOrigin={errorOrigin}
/>
<Diff diff={diff} />
{error ?
<Text>
{stringify({ error })
.trimEnd()
.replace(/^error:([^\n]*\n)?/, chalk.dim('error:$1'))}
</Text>
: <></>}
{code ?
<Text>
{stringify({ code })
.trimEnd()
.replace(/^code:([^\n]*\n)?/, chalk.dim('code:$1'))}
</Text>
: <></>}
{!!Object.keys(otherDiags).length && (
<Text dimColor>{stringify(otherDiags).trimEnd()}</Text>
)}
<Stack stack={stack} />
</Box>
)
}