Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tap reporter: report thrown error messages #2908

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -102,6 +102,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'
];
stdout.should.deepEqual(expectedArray);
});
});
describe('if there is an error stack', function () {
it('should write expected message and stack', function () {
var expectedTitle = 'some title';
Expand Down Expand Up @@ -137,7 +172,45 @@ describe('TAP reporter', function () {
stdout.should.deepEqual(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'
];
stdout.should.deepEqual(expectedArray);
});
});
describe('if there is no error stack or error message', function () {
it('should write expected message only', function () {
var expectedTitle = 'some title';
var countAfterTestEnd = 2;
Expand Down