Skip to content

Commit 0e0f30b

Browse files
committed
fix: add coverage for final error reporting
1 parent 92d66fe commit 0e0f30b

File tree

2 files changed

+100
-5
lines changed

2 files changed

+100
-5
lines changed

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "mocha-runner --reporter spec test/**/*.spec.js",
8-
"coverage": "istanbul cover -x test/**/*.js node_modules/mocha/bin/_mocha -- --reporter spec test/**/*.js"
8+
"coverage": "istanbul cover -x test/**/*.js node_modules/mocha/bin/_mocha -- --reporter spec test/**/*.js",
9+
"precoverage-report": "run-s coverage",
10+
"coverage-report": "istanbul report"
911
},
1012
"repository": {
1113
"type": "git",
@@ -28,6 +30,7 @@
2830
"coveralls": "^2.11.4",
2931
"istanbul": "^0.4.0",
3032
"mocha-runner": "^1.1.1",
33+
"npm-run-all": "^4.0.2",
3134
"rewire": "^2.5.1",
3235
"sinon": "^1.17.2",
3336
"sinon-chai": "^2.8.0"

test/index.spec.js

+96-4
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('SpecReporter', function () {
100100
}
101101
}
102102
it('SpecReporter should allow overriding success icon only', function () {
103-
var expected = 'PASS';
103+
var expected = 'PASS';
104104
var config = createConfigWithPrefixes({ success: expected });
105105
var newSpecReporter = createSpecReporter(config);
106106
newSpecReporter.prefixes.success.should.equal(expected);
@@ -109,7 +109,7 @@ describe('SpecReporter', function () {
109109
});
110110

111111
it('SpecReporter should allow overriding failure icon only', function () {
112-
var expected = 'FAIL';
112+
var expected = 'FAIL';
113113
var config = createConfigWithPrefixes({ failure: expected });
114114
var newSpecReporter = createSpecReporter(config);
115115
newSpecReporter.prefixes.success.should.equal(windowsIcons.success);
@@ -118,7 +118,7 @@ describe('SpecReporter', function () {
118118
});
119119

120120
it('SpecReporter should allow overriding skipped icon only', function () {
121-
var expected = 'SKIPPED';
121+
var expected = 'SKIPPED';
122122
var config = createConfigWithPrefixes({ skipped: expected });
123123
var newSpecReporter = createSpecReporter(config);
124124
newSpecReporter.prefixes.success.should.equal(windowsIcons.success);
@@ -127,7 +127,7 @@ describe('SpecReporter', function () {
127127
});
128128

129129
it('SpecReporter should allow overriding all icons', function () {
130-
var config = createConfigWithPrefixes({
130+
var config = createConfigWithPrefixes({
131131
skipped: 'Skipped',
132132
failure: 'Failed',
133133
success: 'Win!'
@@ -397,6 +397,98 @@ describe('SpecReporter', function () {
397397
});
398398
});
399399

400+
describe('logFinalErrors', function () {
401+
var writtenMessages = [];
402+
beforeEach(function () {
403+
writtenMessages = [];
404+
});
405+
function passThrough(str) {
406+
return str;
407+
}
408+
function createSpecReporter(options) {
409+
var result = new SpecReporter[1](baseReporterDecorator, passThrough, options || {});
410+
result.writeCommonMsg = function (str) {
411+
writtenMessages.push(str);
412+
};
413+
return result;
414+
}
415+
416+
it('should write a single failure out', function () {
417+
var errors = [
418+
{
419+
suite: ['A', 'B'],
420+
description: 'should do stuff',
421+
log: [
422+
'The Error!'
423+
]
424+
}
425+
];
426+
var expected = ['\n\n',
427+
'\u001b[31m1) should do stuff\n\u001b[39m',
428+
'\u001b[31m A B\n\u001b[39m',
429+
' \u001b[90mThe Error!\u001b[39m',
430+
'\n'];
431+
var specReporter = createSpecReporter();
432+
specReporter.logFinalErrors(errors);
433+
writtenMessages.should.eql(expected);
434+
});
435+
436+
it('should truncate messages exceding maxLogLines in length', function () {
437+
var errors = [
438+
{
439+
suite: ['A', 'B'],
440+
description: 'should do stuff',
441+
log: [
442+
'The Error!\nThis line should be discarded'
443+
]
444+
}
445+
];
446+
var expected = ['\n\n',
447+
'\u001b[31m1) should do stuff\n\u001b[39m',
448+
'\u001b[31m A B\n\u001b[39m',
449+
' \u001b[90mThe Error!\u001b[39m',
450+
'\n'];
451+
var specReporter = createSpecReporter({
452+
specReporter: {
453+
maxLogLines: 1
454+
}
455+
});
456+
specReporter.logFinalErrors(errors);
457+
writtenMessages.should.eql(expected);
458+
});
459+
460+
it('should write out multiple failures', function () {
461+
var errors = [
462+
{
463+
suite: ['A', 'B'],
464+
description: 'should do stuff',
465+
log: [
466+
'The Error!'
467+
]
468+
},
469+
{
470+
suite: ['C', 'D'],
471+
description: 'should do more stuff',
472+
log: [
473+
'Another error!'
474+
]
475+
}
476+
];
477+
var expected = ['\n\n',
478+
'\u001b[31m1) should do stuff\n\u001b[39m',
479+
'\u001b[31m A B\n\u001b[39m',
480+
' \u001b[90mThe Error!\u001b[39m',
481+
'\n',
482+
'\u001b[31m2) should do more stuff\n\u001b[39m',
483+
'\u001b[31m C D\n\u001b[39m',
484+
' \u001b[90mAnother error!\u001b[39m',
485+
'\n'];
486+
var specReporter = createSpecReporter();
487+
specReporter.logFinalErrors(errors);
488+
writtenMessages.should.eql(expected);
489+
});
490+
});
491+
400492
describe('onSpecFailure', function () {
401493
describe('with FAIL_FAST option', function () {
402494
var newSpecReporter;

0 commit comments

Comments
 (0)