-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
dot.spec.js
236 lines (205 loc) · 7.1 KB
/
dot.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
'use strict';
var sinon = require('sinon');
var events = require('../../').Runner.constants;
var helpers = require('./helpers');
var reporters = require('../../').reporters;
var Base = reporters.Base;
var Dot = reporters.Dot;
var createMockRunner = helpers.createMockRunner;
var makeRunReporter = helpers.createRunReporterFunction;
var EVENT_RUN_BEGIN = events.EVENT_RUN_BEGIN;
var EVENT_RUN_END = events.EVENT_RUN_END;
var EVENT_TEST_FAIL = events.EVENT_TEST_FAIL;
var EVENT_TEST_PASS = events.EVENT_TEST_PASS;
var EVENT_TEST_PENDING = events.EVENT_TEST_PENDING;
describe('Dot reporter', function () {
var windowWidthStub;
var runReporter = makeRunReporter(Dot);
var noop = function () {};
beforeEach(function () {
windowWidthStub = sinon.stub(Base.window, 'width').value(0);
sinon.stub(Base, 'useColors').value(false);
sinon.stub(Base, 'color').callsFake(function (type, str) {
return type.replace(/ /g, '-') + '_' + str;
});
});
afterEach(function () {
sinon.restore();
});
describe('event handlers', function () {
describe("on 'start' event", function () {
it('should write a newline', function () {
var runner = createMockRunner('start', EVENT_RUN_BEGIN);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
var expectedArray = ['\n'];
expect(stdout, 'to equal', expectedArray);
});
});
describe("on 'pending' event", function () {
describe('when window width is greater than 1', function () {
beforeEach(function () {
windowWidthStub.value(2);
});
it('should write a newline followed by a comma', function () {
var runner = createMockRunner('pending', EVENT_TEST_PENDING);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
var expectedArray = ['\n ', 'pending_' + Base.symbols.comma];
expect(stdout, 'to equal', expectedArray);
});
});
describe('when window width is less than or equal to 1', function () {
it('should write a comma', function () {
var runner = createMockRunner('pending', EVENT_TEST_PENDING);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
var expectedArray = ['pending_' + Base.symbols.comma];
expect(stdout, 'to equal', expectedArray);
});
});
});
describe("on 'pass' event", function () {
var test = {
duration: 1,
slow: function () {
return 2;
}
};
describe('when window width is greater than 1', function () {
beforeEach(function () {
windowWidthStub.value(2);
});
describe('when test speed is fast', function () {
it('should write a newline followed by a dot', function () {
var runner = createMockRunner(
'pass',
EVENT_TEST_PASS,
null,
null,
test
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
expect(test.speed, 'to equal', 'fast');
var expectedArray = ['\n ', 'fast_' + Base.symbols.dot];
expect(stdout, 'to equal', expectedArray);
});
});
});
describe('when window width is less than or equal to 1', function () {
describe('when test speed is fast', function () {
it('should write a grey dot', function () {
var runner = createMockRunner(
'pass',
EVENT_TEST_PASS,
null,
null,
test
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
expect(test.speed, 'to equal', 'fast');
var expectedArray = ['fast_' + Base.symbols.dot];
expect(stdout, 'to equal', expectedArray);
});
});
describe('when test speed is medium', function () {
it('should write a yellow dot', function () {
test.duration = 2;
var runner = createMockRunner(
'pass',
EVENT_TEST_PASS,
null,
null,
test
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
expect(test.speed, 'to equal', 'medium');
var expectedArray = ['medium_' + Base.symbols.dot];
expect(stdout, 'to equal', expectedArray);
});
});
describe('when test speed is slow', function () {
it('should write a bright yellow dot', function () {
test.duration = 3;
var runner = createMockRunner(
'pass',
EVENT_TEST_PASS,
null,
null,
test
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
expect(test.speed, 'to equal', 'slow');
var expectedArray = ['bright-yellow_' + Base.symbols.dot];
expect(stdout, 'to equal', expectedArray);
});
});
});
});
describe("on 'fail' event", function () {
var test = {
test: {
err: 'some error'
}
};
describe('when window width is greater than 1', function () {
beforeEach(function () {
windowWidthStub.value(2);
});
it('should write a newline followed by an exclamation mark', function () {
var runner = createMockRunner(
'fail',
EVENT_TEST_FAIL,
null,
null,
test
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
var expectedArray = ['\n ', 'fail_' + Base.symbols.bang];
expect(stdout, 'to equal', expectedArray);
});
});
describe('when window width is less than or equal to 1', function () {
it('should write an exclamation mark', function () {
var runner = createMockRunner(
'fail',
EVENT_TEST_FAIL,
null,
null,
test
);
var options = {};
var stdout = runReporter({epilogue: noop}, runner, options);
sinon.restore();
var expectedArray = ['fail_' + Base.symbols.bang];
expect(stdout, 'to equal', expectedArray);
});
});
});
describe("on 'end' event", function () {
it('should call epilogue', function () {
var runner = createMockRunner('end', EVENT_RUN_END);
var fakeThis = {
epilogue: sinon.stub()
};
var options = {};
runReporter(fakeThis, runner, options);
sinon.restore();
expect(fakeThis.epilogue.called, 'to be true');
});
});
});
});