From 92afbfe94df674d2fbbe0ba06adb7f17a9dcfe18 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Fri, 14 Dec 2018 12:30:31 -0800 Subject: [PATCH] adding a "retry" event for a test that fails but can be retried; closes #2529 (#3408) Continuation of #2926. Addresses issue #2529 by allowing reporters to take action on tests that have failed but can be retried --- lib/runner.js | 2 ++ test/unit/runner.spec.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/runner.js b/lib/runner.js index e88b11cda3..948f198128 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -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); diff --git a/test/unit/runner.spec.js b/test/unit/runner.spec.js index e7273eaf11..50af94aa5d 100644 --- a/test/unit/runner.spec.js +++ b/test/unit/runner.spec.js @@ -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);