Skip to content

Commit

Permalink
add dot and min report types
Browse files Browse the repository at this point in the history
Re: #921
  • Loading branch information
isaacs committed Sep 27, 2023
1 parent a98e752 commit ee7603c
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/reporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ information than `base`. But otherwise, they are very similar. If
tests pass, it shows a very brief summary. When tests fail, it
shows the same diffs, traces, and so on.

### min

More terse than `terse`. Shows information about failures and
`todo` items, but no summaries, counts, etc. For successful test
runs, this is equivalent to `silent`.

### silent

The `silent` report prints nothing at all to the terminal, but
Expand Down
47 changes: 47 additions & 0 deletions src/reporter/src/dot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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>
)
6 changes: 6 additions & 0 deletions src/reporter/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import { isStream, Minipass } from 'minipass'
import React, { FC } from 'react'
import { Base } from './base.js'
import * as components from './components.js'
import { Dot } from './dot.js'
import * as hooks from './hooks.js'
import { JSONReport, JSONStream } from './json.js'
import { JUnit } from './junit.js'
import { MarkdownStream } from './markdown.js'
import { Min } from './min.js'
import { Terse } from './terse.js'
import * as utils from './utils.js'

export {
Base,
Terse,
Min,
Dot,
JSONReport,
JSONStream,
MarkdownStream,
Expand Down Expand Up @@ -42,6 +46,8 @@ export const addType = (
}
addType('base', Base)
addType('terse', Terse)
addType('min', Min)
addType('dot', Dot)
addType('jsonstream', JSONStream)
addType('json', JSONReport)
addType('junit', JUnit)
Expand Down
15 changes: 15 additions & 0 deletions src/reporter/src/min.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Box } from 'ink'
import React from 'react'
import { Reporter } from './index.js'
import { ResultDetailList } from './result-detail-list.js'

export const Min: Reporter = ({ test }) => (
<Box flexDirection="column">
<ResultDetailList
test={test}
filter={({ parser, counts }) =>
!parser.ok || !!counts.todo || !!counts.fail
}
/>
</Box>
)
54 changes: 54 additions & 0 deletions src/reporter/tap-snapshots/test/dot.tsx.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/dot.tsx > TAP > no comments or passes > must match snapshot 1`] = `
..........
 FAIL  one 1 failed of 1 {TIME}
✖ nope
test/fixtures/get-test.ts 
14  await sleep(64) 
15  // children end out of order 
16  const { subtest: zro } = tb.test('zro', () => {}) 
17  const { subtest: one } = tb.test('one', t => t.fail('nope'))
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ 
18  const { subtest: two } = tb.test('two', t => { 
19  t.pass('skip', { skip: true }) 
20  t.comment('comment in two') 
21  }) 
XXX mock stack XXX
 TODO  fur 1 todo of 1 {TIME}
☐ todo
 TODO  svn 1 todo of 1 {TIME}
☐ todo message
`

exports[`test/dot.tsx > TAP > yes comments and passes > must match snapshot 1`] = `
....................
 FAIL  one 1 failed of 1 {TIME}
✖ nope
test/fixtures/get-test.ts 
14  await sleep(64) 
15  // children end out of order 
16  const { subtest: zro } = tb.test('zro', () => {}) 
17  const { subtest: one } = tb.test('one', t => t.fail('nope'))
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ 
18  const { subtest: two } = tb.test('two', t => { 
19  t.pass('skip', { skip: true }) 
20  t.comment('comment in two') 
21  }) 
XXX mock stack XXX
 TODO  fur 1 todo of 1 {TIME}
☐ todo
 TODO  svn 1 todo of 1 {TIME}
☐ todo message
`
52 changes: 52 additions & 0 deletions src/reporter/tap-snapshots/test/min.tsx.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/min.tsx > TAP > no comments or passes > must match snapshot 1`] = `
 FAIL  one 1 failed of 1 {TIME}
✖ nope
test/fixtures/get-test.ts 
14  await sleep(64) 
15  // children end out of order 
16  const { subtest: zro } = tb.test('zro', () => {}) 
17  const { subtest: one } = tb.test('one', t => t.fail('nope'))
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ 
18  const { subtest: two } = tb.test('two', t => { 
19  t.pass('skip', { skip: true }) 
20  t.comment('comment in two') 
21  }) 
XXX mock stack XXX
 TODO  fur 1 todo of 1 {TIME}
☐ todo
 TODO  svn 1 todo of 1 {TIME}
☐ todo message
`

exports[`test/min.tsx > TAP > yes comments and passes > must match snapshot 1`] = `
 FAIL  one 1 failed of 1 {TIME}
✖ nope
test/fixtures/get-test.ts 
14  await sleep(64) 
15  // children end out of order 
16  const { subtest: zro } = tb.test('zro', () => {}) 
17  const { subtest: one } = tb.test('one', t => t.fail('nope'))
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ 
18  const { subtest: two } = tb.test('two', t => { 
19  t.pass('skip', { skip: true }) 
20  t.comment('comment in two') 
21  }) 
XXX mock stack XXX
 TODO  fur 1 todo of 1 {TIME}
☐ todo
 TODO  svn 1 todo of 1 {TIME}
☐ todo message
`
2 changes: 1 addition & 1 deletion src/reporter/tap-snapshots/test/result-tag.tsx.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports[`test/result-tag.tsx > TAP > fail, with diag, no line/column numbers > m
✖ fake result test/result-tag.tsx
`

exports[`test/result-tag.tsx > TAP > pass, > must match snapshot 1`] = `
exports[`test/result-tag.tsx > TAP > pass > must match snapshot 1`] = `
✓ fake result
`

Expand Down
43 changes: 43 additions & 0 deletions src/reporter/test/dot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import chalk from './fixtures/chalk.js'

import { LoadedConfig } from '@tapjs/config'
import { Box, Text } from 'ink'
import { render } from 'ink-testing-library'
import React from 'react'
import t from 'tap'
import { getTest } from './fixtures/get-test.js'

const config = {} as unknown as LoadedConfig

const { Dot } = (await t.mockImport('../dist/esm/dot.js', {
chalk,
'../dist/esm/ms.js': {
ms: () => '{TIME}',
},
'../dist/esm/hooks/use-test-time.js': {
useTestTime: () => 123,
},
'../dist/esm/stack.js': {
Stack: () => (
<Box>
<Text>{'XXX mock stack XXX'}</Text>
</Box>
),
},
})) as typeof import('../dist/esm/dot.js')

t.test('no comments or passes', async t => {
const tb = getTest()
const app = render(<Dot config={config} test={tb} />)
tb.go()
await tb.concat()
t.matchSnapshot(app.lastFrame())
})

t.test('yes comments and passes', async t => {
const tb = getTest()
const app = render(<Dot config={config} test={tb} />)
tb.go()
await tb.concat()
t.matchSnapshot(app.lastFrame())
})
43 changes: 43 additions & 0 deletions src/reporter/test/min.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import chalk from './fixtures/chalk.js'

import { LoadedConfig } from '@tapjs/config'
import { Box, Text } from 'ink'
import { render } from 'ink-testing-library'
import React from 'react'
import t from 'tap'
import { getTest } from './fixtures/get-test.js'

const config = {} as unknown as LoadedConfig

const { Min } = (await t.mockImport('../dist/esm/min.js', {
chalk,
'../dist/esm/ms.js': {
ms: () => '{TIME}',
},
'../dist/esm/hooks/use-test-time.js': {
useTestTime: () => 123,
},
'../dist/esm/stack.js': {
Stack: () => (
<Box>
<Text>{'XXX mock stack XXX'}</Text>
</Box>
),
},
})) as typeof import('../dist/esm/min.js')

t.test('no comments or passes', async t => {
const tb = getTest()
const app = render(<Min config={config} test={tb} />)
tb.go()
await tb.concat()
t.matchSnapshot(app.lastFrame())
})

t.test('yes comments and passes', async t => {
const tb = getTest()
const app = render(<Min config={config} test={tb} />)
tb.go()
await tb.concat()
t.matchSnapshot(app.lastFrame())
})
2 changes: 1 addition & 1 deletion src/reporter/test/result-tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const getRes = (opts: { [k: string]: any } = {}) =>
opts
) as unknown as Result

t.test('pass, ', t => {
t.test('pass', t => {
t.matchSnapshot(
render(
<ResultTag
Expand Down

0 comments on commit ee7603c

Please sign in to comment.