Skip to content

Commit

Permalink
uncaughtException: report more than one exception per test (#4033)
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba authored and boneskull committed Oct 18, 2019
1 parent ee82d38 commit 3f7b987
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 + '';
Expand Down Expand Up @@ -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);
});
}
Expand Down
16 changes: 16 additions & 0 deletions test/reporters/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3f7b987

Please sign in to comment.