1 | import sinon from 'sinon'
|
2 | import events from 'events'
|
3 | import DotReporter from '../lib/reporter'
|
4 |
|
5 | class BaseReporter extends events.EventEmitter {
|
6 | get symbols () {
|
7 | return {}
|
8 | }
|
9 |
|
10 | get color () {
|
11 | return 'some color'
|
12 | }
|
13 | }
|
14 |
|
15 | var baseReporterMock = new BaseReporter()
|
16 | var reporter, printDotsMock, epilogueMock, resetMock
|
17 |
|
18 | describe('dot reporter', () => {
|
19 | beforeEach(() => {
|
20 | printDotsMock = sinon.spy()
|
21 | epilogueMock = sinon.spy()
|
22 | resetMock = sinon.spy()
|
23 |
|
24 | baseReporterMock.epilogue = epilogueMock
|
25 | baseReporterMock.printDots = printDotsMock
|
26 | baseReporterMock.stats = { reset: resetMock }
|
27 |
|
28 | reporter = new DotReporter(baseReporterMock, {})
|
29 | })
|
30 |
|
31 | it('should print nothing when testrun starts', () => {
|
32 | reporter.printDots = sinon.spy()
|
33 | reporter.emit('start')
|
34 | reporter.printDots.notCalled.should.be.true()
|
35 | })
|
36 |
|
37 | it('should print \\n and call baseReporters epilogue when suite ends', () => {
|
38 | reporter.emit('end')
|
39 | epilogueMock.called.should.be.true()
|
40 | })
|
41 |
|
42 | it('should print pending dots for pending events', () => {
|
43 | reporter.printDots = sinon.spy()
|
44 | reporter.emit('test:pending')
|
45 | reporter.printDots.calledWith('pending').should.be.true()
|
46 | })
|
47 |
|
48 | it('should print pass dots for passing events', () => {
|
49 | reporter.printDots = sinon.spy()
|
50 | reporter.emit('test:pass')
|
51 | reporter.printDots.calledWith('green').should.be.true()
|
52 | })
|
53 |
|
54 | it('should print fail dots for failing events', () => {
|
55 | reporter.printDots = sinon.spy()
|
56 | reporter.emit('test:fail')
|
57 | reporter.printDots.calledWith('fail').should.be.true()
|
58 | })
|
59 |
|
60 | it('should print pending dots for pending events', () => {
|
61 | reporter.printDots = sinon.spy()
|
62 | reporter.emit('test:pending')
|
63 | reporter.printDots.calledWith('pending').should.be.true()
|
64 | })
|
65 |
|
66 | it('should print nothing when test ends', () => {
|
67 | reporter.printDots = sinon.spy()
|
68 | reporter.emit('test:end')
|
69 | reporter.printDots.calledWith(null).should.be.true()
|
70 | })
|
71 |
|
72 | it('printDots should return nothing if status is falsy', () => {
|
73 | (reporter.printDots() === undefined).should.be.true()
|
74 | })
|
75 |
|
76 | describe('should trigger runner:end in watch mode', () => {
|
77 | beforeEach(() => {
|
78 | reporter = new DotReporter(baseReporterMock, { watch: true })
|
79 | })
|
80 |
|
81 | it('should call epiloge in watch mode', () => {
|
82 | reporter.emit('end')
|
83 | epilogueMock.called.should.not.be.true()
|
84 |
|
85 | reporter.emit('runner:end')
|
86 | epilogueMock.called.should.be.true()
|
87 | resetMock.called.should.be.true()
|
88 | })
|
89 | })
|
90 | })
|