Skip to content

Commit

Permalink
Added reason to spec reporter (mochajs#2026)
Browse files Browse the repository at this point in the history
* Added reason to spec reporter

* Added reason tests for spec reporter
  • Loading branch information
rdennis committed Sep 29, 2017
1 parent cb75fdc commit 2441f4f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/reporters/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Spec (runner) {

runner.on('suite', function (suite) {
++indents;
console.log(color('suite', '%s%s'), indent(), suite.title);
console.log(color(suite.pending ? 'pending' : 'suite', '%s%s%s'), indent(), suite.title, suite.reason ? ' (' + suite.reason + ')' : '');
});

runner.on('suite end', function () {
Expand All @@ -48,8 +48,8 @@ function Spec (runner) {
});

runner.on('pending', function (test) {
var fmt = indent() + color('pending', ' - %s');
console.log(fmt, test.title);
var fmt = indent() + color('pending', ' - %s%s');
console.log(fmt, test.title, (test.reason ? ' (' + test.reason + ')' : ''));
});

runner.on('pass', function (test) {
Expand Down
38 changes: 38 additions & 0 deletions test/reporters/spec.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ describe('Spec reporter', function () {
];
stdout.should.deepEqual(expectedArray);
});
it('should return title and reason', function () {
var expectedTitle = 'expectedTitle';
var expectedReason = 'expectedReason';
var suite = {
title: expectedTitle,
reason: expectedReason
};
runner.on = function (event, callback) {
if (event === 'suite') {
callback(suite);
}
};
Spec.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
expectedTitle + ' (' + expectedReason + ')' + '\n'
];
stdout.should.deepEqual(expectedArray);
});
});
describe('on pending', function () {
it('should return title', function () {
Expand All @@ -62,6 +81,25 @@ describe('Spec reporter', function () {
];
stdout.should.deepEqual(expectedArray);
});
it('should return title and reason', function () {
var expectedTitle = 'expectedTitle';
var expectedReason = 'expectedReason';
var suite = {
title: expectedTitle,
reason: expectedReason
};
runner.on = function (event, callback) {
if (event === 'pending') {
callback(suite);
}
};
Spec.call({epilogue: function () {}}, runner);
process.stdout.write = stdoutWrite;
var expectedArray = [
' - ' + expectedTitle + ' (' + expectedReason + ')' + '\n'
];
stdout.should.deepEqual(expectedArray);
});
});
describe('on pass', function () {
describe('if test speed is slow', function () {
Expand Down

0 comments on commit 2441f4f

Please sign in to comment.