-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
dot.tsx
50 lines (47 loc) · 1.23 KB
/
dot.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
import { Box, Text } from 'ink'
import React, { FC, useLayoutEffect, useState } from 'react'
import { TestBase } from '@tapjs/core'
import { Result } from 'tap-parser'
import { Reporter } from './index.js'
import { listenCleanup } from './listen-cleanup.js'
import { ResultDetailList } from './result-detail-list.js'
type Color = 'red' | 'green' | 'cyan' | 'magenta'
const getColor = (r: Result) =>
r.skip ? 'cyan'
: r.todo ? 'magenta'
: !r.ok ? 'red'
: 'green'
const DOTS: Color[] = []
const Dots: FC<{ test: TestBase }> = ({ test }) => {
const [dots, updateDots] = useState<Color[]>([])
useLayoutEffect(
() =>
listenCleanup(test, 'assert', r => {
DOTS.push(getColor(r))
updateDots([...DOTS])
}),
[dots],
)
const width = Math.max(15, columns)
return (
<Box width={width} flexWrap="wrap">
{dots.map((c, i) => (
<Text key={i} color={c}>
.
</Text>
))}
</Box>
)
}
const { columns = 70 } = process.stdout
export const Dot: Reporter = ({ test }) => (
<Box flexDirection="column">
<Dots test={test} />
<ResultDetailList
test={test}
filter={({ parser, counts }) =>
!parser.ok || !!counts.todo || !!counts.fail
}
/>
</Box>
)