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

Conversation

juergba
Copy link
Contributor

@juergba juergba commented Sep 29, 2019

Description

describe('suite', function() {
  it('should report the first of multiple exceptions', function(done) {
    process.nextTick(() => {
      console.log('first');
      throw new Error('first');
    });
    process.nextTick(() => {
      console.log('second');
      done(new Error('second'));
    });
  });
});

The first error is not reported at all, instead the output shows two copies of the second error.

  suite
first
    1) should report the first of multiple exceptions
second
    2) should report the first of multiple exceptions

  0 passing (10ms)
  2 failing

  1) suite
       should report the first of multiple exceptions:
     Error: second
      [...]

  2) suite
       should report the first of multiple exceptions:
     Error: second
      [...]

Description of the Change

  • test.err: currently is storing just one error per test, in case of multiple errors it's the last one. I haven't changed its type to Array for backwards compability and instead introduced a new property test.err.multiple to store additional errors. The latter is set within the EVENT_TEST_FAIL event handler.
  • output: I applied the changes to Base.list() which is part of the epilogue used by most builtin reporters.
  • Reporters as "json" or "XUnit" which don't rely on the Base#epilogue() remain mostly unchanged and do not list multiple errors per test. They list now the first error instead of the last one.

Applicable issues

#2906 partially

@juergba juergba self-assigned this Sep 29, 2019
@coveralls
Copy link

coveralls commented Sep 29, 2019

Coverage Status

Coverage increased (+0.02%) to 92.71% when pulling 7e2782e on juergba/uncaught-double into 2aef07d on master.

@juergba juergba force-pushed the juergba/uncaught-double branch 2 times, most recently from e5cdb72 to a67c118 Compare October 2, 2019 14:46
@juergba juergba added area: async related to asynchronous use of Mocha type: bug a defect, confirmed by a maintainer status: needs review a maintainer should (re-)review this pull request semver-patch implementation requires increase of "patch" version number; "bug fixes" labels Oct 2, 2019
@juergba juergba marked this pull request as ready for review October 2, 2019 15:46
@juergba
Copy link
Contributor Author

juergba commented Oct 12, 2019

I'm going to merge this PR within the next few days.

Copy link
Contributor

@craigtaub craigtaub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@juergba juergba merged commit f78e21f into master Oct 13, 2019
@juergba juergba deleted the juergba/uncaught-double branch October 13, 2019 09:48
@juergba juergba removed the status: needs review a maintainer should (re-)review this pull request label Oct 13, 2019
@juergba juergba added this to the next milestone Oct 13, 2019
@boneskull boneskull modified the milestones: 6.2.1, 6.2.2 Oct 18, 2019
@boneskull boneskull added the landed-on-v6.2.x cherry-picked on v6.2.x branch from master label Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: async related to asynchronous use of Mocha landed-on-v6.2.x cherry-picked on v6.2.x branch from master semver-patch implementation requires increase of "patch" version number; "bug fixes" type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants