UNPKG

1.35 kBJavaScriptView Raw
1import events from 'events'
2
3/**
4 * Initialize a new `Dot` matrix test reporter.
5 *
6 * @param {Runner} runner
7 * @api public
8 */
9class DotReporter extends events.EventEmitter {
10 constructor (baseReporter, config, options = {}) {
11 super()
12
13 this.baseReporter = baseReporter
14 const { epilogue } = this.baseReporter
15
16 this.on('start', () => {
17 console.log()
18 })
19
20 this.on('test:pending', () => {
21 this.printDots('pending')
22 })
23
24 this.on('test:pass', () => {
25 this.printDots('green')
26 })
27
28 this.on('test:fail', () => {
29 this.printDots('fail')
30 })
31
32 this.on('test:end', () => {
33 this.printDots(null)
34 })
35
36 this.on(config.watch ? 'runner:end' : 'end', () => {
37 epilogue.call(baseReporter)
38 console.log()
39
40 if (config.watch) {
41 baseReporter.printEpilogue = true
42 baseReporter.stats.reset()
43 }
44 })
45 }
46
47 printDots (status) {
48 const { color, symbols } = this.baseReporter
49 const symbol = status === 'fail' ? 'F' : symbols.dot
50
51 if (!status) {
52 return
53 }
54
55 /* istanbul ignore next */
56 process.stdout.write(color(status, symbol))
57 }
58}
59
60export default DotReporter