42310368dd010ddc425c2411a47caf5a4045fcc5.svn-base
2.62 KB
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
85
86
87
88
89
90
const React = require('react')
const {Box, Color} = require('ink')
const util = require('util')
const counts = require('./counts.js')
const chalk = require('chalk')
const yaml = require('tap-yaml')
const ms = require('ms')
const importJSX = require('import-jsx')
const AssertName = importJSX('./assert-name.js')
const StatusMark = importJSX('./status-mark.js')
const showYaml = test =>
test.results && !test.results.ok && !test.lists.fail.length &&
(test.options.exitCode || test.options.signal)
const lists = test => (
<Box flexDirection="column" marginBottom={
showYaml(test) ||
test.lists.fail.length ||
test.lists.todo.length ||
test.lists.skip.length ? 1 : 0 }>
{ test.lists.fail.length ? (
<Box flexDirection="column">
{ test.lists.fail.map((res, i) => (
<AssertName {...res} key={''+i} />
))}
</Box>
) : ''}
{ test.lists.todo.length ? (
<Box flexDirection="column">
{ test.lists.todo.map((res, i) => (
<AssertName {...res} key={''+i} />
))}
</Box>
) : ''}
{ test.lists.skip.length ? (
<Box flexDirection="column">
{ test.lists.skip.map((res, i) => (
<AssertName {...res} key={''+i} />
))}
</Box>
) : ''}
{ // cases where no tests fail, but the test fails
// eg, exiting with non-zero code, being killed, etc.
showYaml(test) ? (
<Box>{' ' + yaml.stringify({
command: test.options.command,
args: test.options.args,
exitCode: test.options.exitCode,
signal: test.options.signal,
}).replace(/\n/g, '\n ').trimRight()}</Box>) : '' }
{printBail(test.results)}
</Box>
)
const skipOrTodoReason = test =>
test.options.skip && test.options.skip !== true
? ` > ${chalk.cyan(test.options.skip)}`
: test.options.todo && test.options.todo !== true
? ` > ${chalk.magenta(test.options.todo)}`
: ''
const printBail = results =>
!results || !results.bailout ? ''
: <Box marginTop={1}>{chalk.bold.red('BAILOUT ') + results.bailout}</Box>
const printLists = test =>
test.results && (
test.results.bailout ||
!test.results.ok ||
test.counts.pass !== test.counts.total
)
const time = (time, start, end) =>
!start ? (<Color dim>{' ...'}</Color>)
: (<Color hex="#aaa" bold>{
ms(time || (end || Date.now()) - start)}</Color>)
module.exports = ({test}) => (
<Box flexDirection="column">
<Box>
<StatusMark test={test} />
{' ' + test.name + skipOrTodoReason(test)}
{counts(test.counts)}
{time(test.time, test.startTime, test.endTime)}
</Box>
{ printLists(test) ? lists(test) : '' }
</Box>
)