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

uncaughtException: report more than one exception per test #4033

Merged
merged 2 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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