/
printErrors.spec.js
58 lines (53 loc) · 1.28 KB
/
printErrors.spec.js
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
import Listr from 'listr'
import makeConsoleMock from 'consolemock'
import printErrors from '../lib/printErrors'
describe('printErrors', () => {
const logger = makeConsoleMock()
beforeEach(() => {
logger.clearHistory()
})
it('should print plain errors', () => {
const err = new Error('We have a problem')
printErrors(err, logger)
expect(logger.printHistory()).toMatchSnapshot()
})
it('should print Listr nested errors', async () => {
expect.assertions(1)
const list = new Listr(
[
{
title: 'foo',
task: () => Promise.reject(new Error('Foo failed'))
},
{
title: 'bar',
task: () =>
new Listr([
{
title: 'unicorn',
task: () => Promise.reject(new Error('Unicorn failed'))
},
{
title: 'rainbow',
task: () => Promise.resolve()
}
])
},
{
title: 'baz',
task: () => Promise.resolve()
}
],
{
exitOnError: false,
renderer: 'silent'
}
)
try {
await list.run()
} catch (err) {
printErrors(err, logger)
expect(logger.printHistory()).toMatchSnapshot()
}
})
})