karma-runner / karma-mocha

A Karma plugin. Adapter for Mocha testing framework.
MIT License
379 stars 94 forks source link

adapter.js swallows failures that occur after test complete #236

Open samouri opened 3 years ago

samouri commented 3 years ago

summary As rarely used as it is, Mocha currently supports marking a test as failed after it has already completed.

As an example, here is a unit test from mocha's own suite (src):

describe('fail the test from the "after each" hook', function() { 
   it('should fail', function() { 
     // but not here 
   }); 

   afterEach(function() { 
     this.test.error(new Error('failing from after each')); 
   }); 
 }); 

This code branch needs to call karma.report in the case of test.type === 'test': https://github.com/karma-runner/karma-mocha/blob/537ef7bafb2a1c78c32ba9d54ca3bef877c52c34/src/adapter.js#L164-L171

Is this something maintainers would be willing to accept a PR on?

Thanks!