Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
adding a "retry" event for a test that fails but can be retried; closes
Browse files Browse the repository at this point in the history
mochajs#2529 (mochajs#3408)

Continuation of mochajs#2926.  

Addresses issue mochajs#2529 by allowing reporters to take action on tests that have failed but can be retried
  • Loading branch information
boneskull authored Dec 14, 2018
1 parent a309ea3 commit 92afbfe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,8 @@ Runner.prototype.runTests = function(suite, fn) {
clonedTest.currentRetry(retry + 1);
tests.unshift(clonedTest);

self.emit('retry', test, err);

// Early return + hook trigger so that it doesn't
// increment the count wrong
return self.hookUp('afterEach', next);
Expand Down
30 changes: 30 additions & 0 deletions test/unit/runner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,36 @@ describe('Runner', function() {
});
});

describe('.run(fn)', function() {
it('should emit "retry" when a retryable test fails', function(done) {
var retries = 2;
var retryableFails = 0;
var err = new Error('bear error');

var test = new Test('im a test about bears', function() {
if (retryableFails < retries) {
throw err;
}
});

suite.retries(retries);
suite.addTest(test);

runner.on('retry', function(testClone, testErr) {
retryableFails += 1;
expect(testClone.title, 'to be', test.title);
expect(testErr, 'to be', err);
});

runner.run(function(failures) {
expect(failures, 'to be', 0);
expect(retryableFails, 'to be', retries);

done();
});
});
});

describe('allowUncaught', function() {
it('should allow unhandled errors to propagate through', function(done) {
var newRunner = new Runner(suite);
Expand Down

0 comments on commit 92afbfe

Please sign in to comment.