From 3f7b9873e65021b2132377b740d6f040eb62ddd1 Mon Sep 17 00:00:00 2001 From: Juerg B <44573692+juergba@users.noreply.github.com> Date: Sun, 13 Oct 2019 11:23:13 +0200 Subject: [PATCH] uncaughtException: report more than one exception per test (#4033) --- lib/reporters/base.js | 19 +++++++++++++++++-- test/reporters/base.spec.js | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index 69db8f8ac7..e5ed0d4c61 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -197,6 +197,7 @@ var generateDiff = (exports.generateDiff = function(actual, expected) { * Error property */ exports.list = function(failures) { + var multipleErr, multipleTest; Base.consoleLog(); failures.forEach(function(test, i) { // format @@ -207,7 +208,16 @@ exports.list = function(failures) { // msg var msg; - var err = test.err; + var err; + if (test.err && test.err.multiple) { + if (multipleTest !== test) { + multipleTest = test; + multipleErr = [test.err].concat(test.err.multiple); + } + err = multipleErr.shift(); + } else { + err = test.err; + } var message; if (err.message && typeof err.message.toString === 'function') { message = err.message + ''; @@ -298,7 +308,12 @@ function Base(runner, options) { if (showDiff(err)) { stringifyDiffObjs(err); } - test.err = err; + // more than one error per test + if (test.err && err instanceof Error) { + test.err.multiple = (test.err.multiple || []).concat(err); + } else { + test.err = err; + } failures.push(test); }); } diff --git a/test/reporters/base.spec.js b/test/reporters/base.spec.js index 80957c39aa..18867ae6fa 100644 --- a/test/reporters/base.spec.js +++ b/test/reporters/base.spec.js @@ -417,6 +417,22 @@ describe('Base reporter', function() { expect(errOut, 'to be', '1) test title:\n Error\n foo\n bar'); }); + it('should list multiple Errors per test', function() { + var err = new Error('First Error'); + err.multiple = [new Error('Second Error - same test')]; + var test = makeTest(err); + + list([test, test]); + + var errOut = stdout.join('\n').trim(); + expect( + errOut, + 'to contain', + 'Error: First Error', + 'Error: Second Error - same test' + ); + }); + describe('when reporter output immune to user test changes', function() { var sandbox; var baseConsoleLog;