From c284e618f60e886ccc12a4bdec2e9cc9781ee3f9 Mon Sep 17 00:00:00 2001 From: Krzysztof Jan Modras Date: Sat, 1 Jul 2017 20:16:38 +0200 Subject: [PATCH 1/2] Tap reporter: report thrown error messages --- lib/reporters/tap.js | 3 ++ test/reporters/tap.spec.js | 75 +++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/lib/reporters/tap.js b/lib/reporters/tap.js index 4e99165f8f..7e2fbae720 100644 --- a/lib/reporters/tap.js +++ b/lib/reporters/tap.js @@ -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, ' ')); } diff --git a/test/reporters/tap.spec.js b/test/reporters/tap.spec.js index 6a29ffbe26..9faadbda71 100644 --- a/test/reporters/tap.spec.js +++ b/test/reporters/tap.spec.js @@ -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' + ]; + stdout.should.deepEqual(expectedArray); + }); + }); describe('if there is an error stack', function () { it('should write expected message and stack', function () { var expectedStack = 'some stack'; @@ -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' + ]; + stdout.should.deepEqual(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) { From 86681d17046f56badb8f6c394eeb148ee5c1ce30 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Sat, 7 Apr 2018 15:42:29 -0700 Subject: [PATCH 2/2] fix assertions Signed-off-by: Christopher Hiller --- test/reporters/tap.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/reporters/tap.spec.js b/test/reporters/tap.spec.js index 9faadbda71..9b7eac9491 100644 --- a/test/reporters/tap.spec.js +++ b/test/reporters/tap.spec.js @@ -112,7 +112,7 @@ describe('TAP reporter', function () { 'not ok ' + countAfterTestEnd + ' ' + expectedTitle + '\n', ' ' + expectedErrorMessage + '\n' ]; - stdout.should.deepEqual(expectedArray); + expect(stdout).to.eql(expectedArray); }); }); describe('if there is an error stack', function () { @@ -170,7 +170,7 @@ describe('TAP reporter', function () { ' ' + expectedErrorMessage + '\n', ' ' + expectedStack + '\n' ]; - stdout.should.deepEqual(expectedArray); + expect(stdout).to.eql(expectedArray); }); }); describe('if there is no error stack or error message', function () {