Skip to content

Commit

Permalink
Tap reporter: report thrown error messages (#3317)
Browse files Browse the repository at this point in the history
original work by @chrmod; continuation of PR #2908. 

BREAKING CHANGES; SEMVER MAJOR

Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
  • Loading branch information
boneskull committed Apr 8, 2018
1 parent 741b0bd commit 1acea30
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/reporters/tap.js
Expand Up @@ -46,6 +46,9 @@ function TAP (runner) {
runner.on('fail', function (test, err) {
failures++;
console.log('not ok %d %s', n, title(test));
if (err.message) {
console.log(err.message.replace(/^/gm, ' '));
}
if (err.stack) {
console.log(err.stack.replace(/^/gm, ' '));
}
Expand Down
75 changes: 74 additions & 1 deletion test/reporters/tap.spec.js
Expand Up @@ -80,6 +80,41 @@ describe('TAP reporter', function () {
});

describe('on fail', function () {
describe('if there is an error message', function () {
it('should write expected message and error message', function () {
var expectedTitle = 'some title';
var countAfterTestEnd = 2;
var expectedErrorMessage = 'some error';
var test = {
fullTitle: function () {
return expectedTitle;
},
slow: function () {}
};
var error = {
message: expectedErrorMessage
};
runner.on = function (event, callback) {
if (event === 'test end') {
callback();
}
if (event === 'fail') {
callback(test, error);
}
};
runner.suite = '';
runner.grepTotal = function () { };
TAP.call({}, runner);

process.stdout.write = stdoutWrite;

var expectedArray = [
'not ok ' + countAfterTestEnd + ' ' + expectedTitle + '\n',
' ' + expectedErrorMessage + '\n'
];
expect(stdout).to.eql(expectedArray);
});
});
describe('if there is an error stack', function () {
it('should write expected message and stack', function () {
var expectedStack = 'some stack';
Expand All @@ -100,7 +135,45 @@ describe('TAP reporter', function () {
expect(stdout).to.eql(expectedArray);
});
});
describe('if there is no error stack', function () {
describe('if there is an error stack and error message', function () {
it('should write expected message and stack', function () {
var expectedTitle = 'some title';
var countAfterTestEnd = 2;
var expectedStack = 'some stack';
var expectedErrorMessage = 'some error';
var test = {
fullTitle: function () {
return expectedTitle;
},
slow: function () {}
};
var error = {
stack: expectedStack,
message: expectedErrorMessage
};
runner.on = function (event, callback) {
if (event === 'test end') {
callback();
}
if (event === 'fail') {
callback(test, error);
}
};
runner.suite = '';
runner.grepTotal = function () { };
TAP.call({}, runner);

process.stdout.write = stdoutWrite;

var expectedArray = [
'not ok ' + countAfterTestEnd + ' ' + expectedTitle + '\n',
' ' + expectedErrorMessage + '\n',
' ' + expectedStack + '\n'
];
expect(stdout).to.eql(expectedArray);
});
});
describe('if there is no error stack or error message', function () {
it('should write expected message only', function () {
var error = {};
runner.on = runner.once = function (event, callback) {
Expand Down

0 comments on commit 1acea30

Please sign in to comment.