Skip to content

Commit

Permalink
fix: add coverage for final error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffynuts committed Mar 15, 2017
1 parent 92d66fe commit 0e0f30b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 5 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"main": "index.js",
"scripts": {
"test": "mocha-runner --reporter spec test/**/*.spec.js",
"coverage": "istanbul cover -x test/**/*.js node_modules/mocha/bin/_mocha -- --reporter spec test/**/*.js"
"coverage": "istanbul cover -x test/**/*.js node_modules/mocha/bin/_mocha -- --reporter spec test/**/*.js",
"precoverage-report": "run-s coverage",
"coverage-report": "istanbul report"
},
"repository": {
"type": "git",
Expand All @@ -28,6 +30,7 @@
"coveralls": "^2.11.4",
"istanbul": "^0.4.0",
"mocha-runner": "^1.1.1",
"npm-run-all": "^4.0.2",
"rewire": "^2.5.1",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0"
Expand Down
100 changes: 96 additions & 4 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('SpecReporter', function () {
}
}
it('SpecReporter should allow overriding success icon only', function () {
var expected = 'PASS';
var expected = 'PASS';
var config = createConfigWithPrefixes({ success: expected });
var newSpecReporter = createSpecReporter(config);
newSpecReporter.prefixes.success.should.equal(expected);
Expand All @@ -109,7 +109,7 @@ describe('SpecReporter', function () {
});

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

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

it('SpecReporter should allow overriding all icons', function () {
var config = createConfigWithPrefixes({
var config = createConfigWithPrefixes({
skipped: 'Skipped',
failure: 'Failed',
success: 'Win!'
Expand Down Expand Up @@ -397,6 +397,98 @@ describe('SpecReporter', function () {
});
});

describe('logFinalErrors', function () {
var writtenMessages = [];
beforeEach(function () {
writtenMessages = [];
});
function passThrough(str) {
return str;
}
function createSpecReporter(options) {
var result = new SpecReporter[1](baseReporterDecorator, passThrough, options || {});
result.writeCommonMsg = function (str) {
writtenMessages.push(str);
};
return result;
}

it('should write a single failure out', function () {
var errors = [
{
suite: ['A', 'B'],
description: 'should do stuff',
log: [
'The Error!'
]
}
];
var expected = ['\n\n',
'\u001b[31m1) should do stuff\n\u001b[39m',
'\u001b[31m A B\n\u001b[39m',
' \u001b[90mThe Error!\u001b[39m',
'\n'];
var specReporter = createSpecReporter();
specReporter.logFinalErrors(errors);
writtenMessages.should.eql(expected);
});

it('should truncate messages exceding maxLogLines in length', function () {
var errors = [
{
suite: ['A', 'B'],
description: 'should do stuff',
log: [
'The Error!\nThis line should be discarded'
]
}
];
var expected = ['\n\n',
'\u001b[31m1) should do stuff\n\u001b[39m',
'\u001b[31m A B\n\u001b[39m',
' \u001b[90mThe Error!\u001b[39m',
'\n'];
var specReporter = createSpecReporter({
specReporter: {
maxLogLines: 1
}
});
specReporter.logFinalErrors(errors);
writtenMessages.should.eql(expected);
});

it('should write out multiple failures', function () {
var errors = [
{
suite: ['A', 'B'],
description: 'should do stuff',
log: [
'The Error!'
]
},
{
suite: ['C', 'D'],
description: 'should do more stuff',
log: [
'Another error!'
]
}
];
var expected = ['\n\n',
'\u001b[31m1) should do stuff\n\u001b[39m',
'\u001b[31m A B\n\u001b[39m',
' \u001b[90mThe Error!\u001b[39m',
'\n',
'\u001b[31m2) should do more stuff\n\u001b[39m',
'\u001b[31m C D\n\u001b[39m',
' \u001b[90mAnother error!\u001b[39m',
'\n'];
var specReporter = createSpecReporter();
specReporter.logFinalErrors(errors);
writtenMessages.should.eql(expected);
});
});

describe('onSpecFailure', function () {
describe('with FAIL_FAST option', function () {
var newSpecReporter;
Expand Down

0 comments on commit 0e0f30b

Please sign in to comment.