mocha: Duplicated failing test summary

Running Mocha 3.4.2 on Node 8.1.3 (also reproducible on Node 7.6.0).

describe('mocha', 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'));
    });
  });
});

Output:

$ mocha 


  multiple errors
first
    1) should report on multiple uncaught exceptions
second
    2) should report on multiple uncaught exceptions


  0 passing (12ms)
  2 failing

  1) multiple errors should report on multiple uncaught exceptions:
     Error: second
      at process.nextTick (test/index.js:9:12)
      at _combinedTickCallback (internal/process/next_tick.js:95:7)
      at Immediate._tickCallback (internal/process/next_tick.js:161:9)

  2) multiple errors should report on multiple uncaught exceptions:
     Error: second
      at process.nextTick (test/index.js:9:12)
      at _combinedTickCallback (internal/process/next_tick.js:95:7)
      at Immediate._tickCallback (internal/process/next_tick.js:161:9)




  0 passing (14ms)
  2 failing

  1) multiple errors should report on multiple uncaught exceptions:
     Error: second
      at process.nextTick (test/index.js:9:12)
      at _combinedTickCallback (internal/process/next_tick.js:95:7)
      at Immediate._tickCallback (internal/process/next_tick.js:161:9)

  2) multiple errors should report on multiple uncaught exceptions:
     Error: second
      at process.nextTick (test/index.js:9:12)
      at _combinedTickCallback (internal/process/next_tick.js:95:7)
      at Immediate._tickCallback (internal/process/next_tick.js:161:9)




Not only does mocha output four (!) copies of the second error, it fails to output any copies of the first error. This makes it difficult to debug tests if the second error is merely a symptom of the first.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (11 by maintainers)

Most upvoted comments

Those would need to be reported, but should not re-run any of Mocha’s test run logic (that says “ok, that test is done, do the hooks, now do the next one; ok, that suite is done, do its after hooks, are we at the end? do the end…”). It should be entirely possible to get the logic un-repeatable with promises while leaving the immediate handlers for various test/hook results in a state where they’ll emit a failure to the reporter – not that it would be easy, but the hard part isn’t leaving those handlers still correctly reporting redundant test/hook completions; the hard part is changing Mocha’s overcomplex internals and using promises under the hood of a callback-based API.