Skip to content

Commit f42cbf4

Browse files
authored
Merge pull request #2701 from craigtaub/landingSpec
Increase tests coverage for landing, min, tap and list reporters
2 parents d051ec1 + 6065242 commit f42cbf4

File tree

4 files changed

+637
-0
lines changed

4 files changed

+637
-0
lines changed

test/reporters/landing.spec.js

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
'use strict';
2+
3+
var reporters = require('../../').reporters;
4+
var Landing = reporters.Landing;
5+
var Base = reporters.Base;
6+
7+
describe('Landing reporter', function () {
8+
var stdout;
9+
var stdoutWrite;
10+
var runner;
11+
var useColors;
12+
var windowWidth;
13+
var resetCode = '\u001b[0m';
14+
15+
beforeEach(function () {
16+
stdout = [];
17+
runner = {};
18+
stdoutWrite = process.stdout.write;
19+
process.stdout.write = function (string) {
20+
stdout.push(string);
21+
};
22+
useColors = Base.useColors;
23+
Base.useColors = false;
24+
windowWidth = Base.window.width;
25+
Base.window.width = 1;
26+
});
27+
28+
afterEach(function () {
29+
Base.useColors = useColors;
30+
Base.window.width = windowWidth;
31+
});
32+
33+
describe('on start', function () {
34+
it('should write new lines', function () {
35+
var cachedCursor = Base.cursor;
36+
Base.cursor.hide = function () {};
37+
runner.on = function (event, callback) {
38+
if (event === 'start') {
39+
callback();
40+
}
41+
};
42+
Landing.call({}, runner);
43+
44+
process.stdout.write = stdoutWrite;
45+
46+
stdout[0].should.deepEqual('\n\n\n ');
47+
Base.cursor = cachedCursor;
48+
});
49+
50+
it('should call cursor hide', function () {
51+
var cachedCursor = Base.cursor;
52+
var calledCursorHide = false;
53+
Base.cursor.hide = function () {
54+
calledCursorHide = true;
55+
};
56+
runner.on = function (event, callback) {
57+
if (event === 'start') {
58+
callback();
59+
}
60+
};
61+
Landing.call({}, runner);
62+
63+
process.stdout.write = stdoutWrite;
64+
calledCursorHide.should.be.true();
65+
66+
Base.cursor = cachedCursor;
67+
});
68+
});
69+
70+
describe('on test end', function () {
71+
describe('if test has failed', function () {
72+
it('should write expected landing strip', function () {
73+
var test = {
74+
state: 'failed'
75+
};
76+
runner.on = function (event, callback) {
77+
if (event === 'test end') {
78+
callback(test);
79+
}
80+
};
81+
runner.total = 12;
82+
Landing.call({}, runner);
83+
84+
process.stdout.write = stdoutWrite;
85+
86+
var expectedArray = [
87+
'\u001b[1D\u001b[2A',
88+
' ',
89+
'\n ',
90+
'',
91+
'✈',
92+
'\n',
93+
' ',
94+
resetCode
95+
];
96+
stdout.should.deepEqual(expectedArray);
97+
});
98+
});
99+
describe('if test has not failed', function () {
100+
it('should write expected landing strip', function () {
101+
var test = {
102+
state: 'success'
103+
};
104+
runner.on = function (event, callback) {
105+
if (event === 'test end') {
106+
callback(test);
107+
}
108+
};
109+
110+
Landing.call({}, runner);
111+
112+
process.stdout.write = stdoutWrite;
113+
114+
var expectedArray = [
115+
'\u001b[1D\u001b[2A',
116+
' ',
117+
'\n ',
118+
'',
119+
'✈',
120+
'\n',
121+
' ',
122+
resetCode
123+
];
124+
stdout.should.deepEqual(expectedArray);
125+
});
126+
});
127+
});
128+
describe('on end', function () {
129+
it('should call cursor show and epilogue', function () {
130+
var cachedCursor = Base.cursor;
131+
var calledCursorShow = false;
132+
Base.cursor.show = function () {
133+
calledCursorShow = true;
134+
};
135+
runner.on = function (event, callback) {
136+
if (event === 'end') {
137+
callback();
138+
}
139+
};
140+
var calledEpilogue = false;
141+
Landing.call({
142+
epilogue: function () {
143+
calledEpilogue = true;
144+
}
145+
}, runner);
146+
147+
process.stdout.write = stdoutWrite;
148+
calledEpilogue.should.be.true();
149+
calledCursorShow.should.be.true();
150+
151+
Base.cursor = cachedCursor;
152+
});
153+
});
154+
});

test/reporters/list.spec.js

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
'use strict';
2+
3+
var reporters = require('../../').reporters;
4+
var List = reporters.List;
5+
var Base = reporters.Base;
6+
7+
describe('List reporter', function () {
8+
var stdout;
9+
var stdoutWrite;
10+
var runner;
11+
var useColors;
12+
13+
beforeEach(function () {
14+
stdout = [];
15+
runner = {};
16+
stdoutWrite = process.stdout.write;
17+
process.stdout.write = function (string) {
18+
stdout.push(string);
19+
};
20+
useColors = Base.useColors;
21+
Base.useColors = false;
22+
});
23+
24+
afterEach(function () {
25+
Base.useColors = useColors;
26+
});
27+
28+
describe('on start and test', function () {
29+
it('should write expected new line and title to the console', function () {
30+
var expectedTitle = 'some title';
31+
var test = {
32+
fullTitle: function () {
33+
return expectedTitle;
34+
}
35+
};
36+
runner.on = function (event, callback) {
37+
if (event === 'start') {
38+
callback();
39+
}
40+
if (event === 'test') {
41+
callback(test);
42+
}
43+
};
44+
List.call({epilogue: function () {}}, runner);
45+
46+
process.stdout.write = stdoutWrite;
47+
var startString = '\n';
48+
var testString = ' ' + expectedTitle + ': ';
49+
var expectedArray = [
50+
startString,
51+
testString
52+
];
53+
stdout.should.deepEqual(expectedArray);
54+
});
55+
});
56+
describe('on pending', function () {
57+
it('should write expected title to the console', function () {
58+
var expectedTitle = 'some title';
59+
var test = {
60+
fullTitle: function () {
61+
return expectedTitle;
62+
}
63+
};
64+
runner.on = function (event, callback) {
65+
if (event === 'pending') {
66+
callback(test);
67+
}
68+
};
69+
List.call({epilogue: function () {}}, runner);
70+
71+
process.stdout.write = stdoutWrite;
72+
73+
stdout[0].should.deepEqual(' - ' + expectedTitle + '\n');
74+
});
75+
});
76+
describe('on pass', function () {
77+
it('should call cursor CR', function () {
78+
var calledCursorCR = false;
79+
var cachedCursor = Base.cursor;
80+
Base.cursor.CR = function () {
81+
calledCursorCR = true;
82+
};
83+
var expectedTitle = 'some title';
84+
var expectedDuration = 100;
85+
var test = {
86+
fullTitle: function () {
87+
return expectedTitle;
88+
},
89+
duration: expectedDuration,
90+
slow: function () {}
91+
};
92+
runner.on = function (event, callback) {
93+
if (event === 'pass') {
94+
callback(test);
95+
}
96+
};
97+
List.call({epilogue: function () {}}, runner);
98+
99+
process.stdout.write = stdoutWrite;
100+
101+
calledCursorCR.should.be.true();
102+
103+
Base.cursor = cachedCursor;
104+
});
105+
it('should write expected symbol, title and duration to the console', function () {
106+
var cachedSymbols = Base.symbols;
107+
var expectedOkSymbol = 'OK';
108+
Base.symbols.ok = expectedOkSymbol;
109+
var cachedCursor = Base.cursor;
110+
Base.cursor.CR = function () {};
111+
var expectedTitle = 'some title';
112+
var expectedDuration = 100;
113+
var test = {
114+
fullTitle: function () {
115+
return expectedTitle;
116+
},
117+
duration: expectedDuration,
118+
slow: function () {}
119+
};
120+
runner.on = function (event, callback) {
121+
if (event === 'pass') {
122+
callback(test);
123+
}
124+
};
125+
List.call({epilogue: function () {}}, runner);
126+
127+
process.stdout.write = stdoutWrite;
128+
129+
stdout[0].should.equal(' ' + expectedOkSymbol + ' ' + expectedTitle + ': ' + expectedDuration + 'ms\n');
130+
131+
Base.cursor = cachedCursor;
132+
Base.symbols = cachedSymbols;
133+
});
134+
});
135+
describe('on fail', function () {
136+
it('should call cursor CR', function () {
137+
var calledCursorCR = false;
138+
var cachedCursor = Base.cursor;
139+
Base.cursor.CR = function () {
140+
calledCursorCR = true;
141+
};
142+
var expectedTitle = 'some title';
143+
var expectedDuration = 100;
144+
var test = {
145+
fullTitle: function () {
146+
return expectedTitle;
147+
},
148+
duration: expectedDuration,
149+
slow: function () {}
150+
};
151+
runner.on = function (event, callback) {
152+
if (event === 'fail') {
153+
callback(test);
154+
}
155+
};
156+
List.call({epilogue: function () {}}, runner);
157+
158+
process.stdout.write = stdoutWrite;
159+
160+
calledCursorCR.should.be.true();
161+
162+
Base.cursor = cachedCursor;
163+
});
164+
it('should write expected error number and title', function () {
165+
var cachedCursor = Base.cursor;
166+
var expectedErrorCount = 1;
167+
Base.cursor.CR = function () {};
168+
var expectedTitle = 'some title';
169+
var expectedDuration = 100;
170+
var test = {
171+
fullTitle: function () {
172+
return expectedTitle;
173+
},
174+
duration: expectedDuration,
175+
slow: function () {}
176+
};
177+
runner.on = function (event, callback) {
178+
if (event === 'fail') {
179+
callback(test);
180+
}
181+
};
182+
runner.on = function (event, callback) {
183+
if (event === 'fail') {
184+
callback(test);
185+
}
186+
};
187+
List.call({epilogue: function () {}}, runner);
188+
189+
process.stdout.write = stdoutWrite;
190+
191+
stdout[0].should.equal(' ' + expectedErrorCount + ') ' + expectedTitle + '\n');
192+
193+
Base.cursor = cachedCursor;
194+
});
195+
});
196+
197+
describe('on end', function () {
198+
it('should call epilogue', function () {
199+
var calledEpilogue = false;
200+
runner.on = function (event, callback) {
201+
if (event === 'end') {
202+
callback();
203+
}
204+
};
205+
List.call({
206+
epilogue: function () {
207+
calledEpilogue = true;
208+
}
209+
}, runner);
210+
process.stdout.write = stdoutWrite;
211+
212+
calledEpilogue.should.be.true();
213+
});
214+
});
215+
});

0 commit comments

Comments
 (0)