From 4586186a0b907bfc612ac95dd2145b9b59dc654f Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Fri, 14 Jul 2017 13:53:59 -0400 Subject: [PATCH 1/5] adding a "retryable fail" event for a test that fails but can be retried Addresses issue #2592 by allowing reporters to take action on tests that have failed but can be retried --- lib/runner.js | 2 ++ test/unit/runner.spec.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/runner.js b/lib/runner.js index 039065a2e0..a3fc31278a 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -558,6 +558,8 @@ Runner.prototype.runTests = function (suite, fn) { clonedTest.currentRetry(retry + 1); tests.unshift(clonedTest); + self.emit('retryable fail', 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 718a9b7cf6..3028bf693a 100644 --- a/test/unit/runner.spec.js +++ b/test/unit/runner.spec.js @@ -373,6 +373,37 @@ describe('Runner', function () { }); }); + describe('.run(fn)', function () { + it('should emit "retryable fail" when a retryable test fails', function (done) { + var retries = 2; + var retryableFails = 0; + + var test = new Test('im a test about bears', function () { + if (retryableFails < retries) { + throw new Error('bear error'); + } + }); + + test.retries(retries); + suite.retries(retries); + suite.addTest(test); + + runner.on('retryable fail', function (test, err) { + retryableFails += 1; + + expect(test).to.equal(test); + expect(err).to.equal(err); + }); + + runner.run(function (failures) { + expect(failures).to.equal(0); + expect(retryableFails).to.equal(retries); + + done(); + }); + }); + }); + describe('allowUncaught', function () { it('should allow unhandled errors to propagate through', function (done) { var newRunner = new Runner(suite); From d6e360b768f23ad756e45e22542e9d13187157eb Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Mon, 17 Jul 2017 10:30:29 -0400 Subject: [PATCH 2/5] fixing an issue with scope in a test --- test/unit/runner.spec.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/unit/runner.spec.js b/test/unit/runner.spec.js index 3028bf693a..0d05ee40d4 100644 --- a/test/unit/runner.spec.js +++ b/test/unit/runner.spec.js @@ -377,22 +377,25 @@ describe('Runner', function () { it('should emit "retryable fail" 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 () { + var TEST = new Test('im a test about bears', function () { if (retryableFails < retries) { - throw new Error('bear error'); + throw ERR; } }); - test.retries(retries); + TEST.retries(retries); suite.retries(retries); - suite.addTest(test); + suite.addTest(TEST); runner.on('retryable fail', function (test, err) { retryableFails += 1; - expect(test).to.equal(test); - expect(err).to.equal(err); + // retries clone the tests, so I guess comparing the test + // names should be enough + expect(test.title).to.equal(TEST.title); + expect(err).to.equal(ERR); }); runner.run(function (failures) { From 6da940f4f3b32592174fb74c97d3a3ad5cfe4bd4 Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Thu, 17 May 2018 22:05:19 -0400 Subject: [PATCH 3/5] fixing lint errors --- test/unit/runner.spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/runner.spec.js b/test/unit/runner.spec.js index b4aa333168..0ec0e3d187 100644 --- a/test/unit/runner.spec.js +++ b/test/unit/runner.spec.js @@ -385,13 +385,13 @@ describe('Runner', function() { }); }); - describe('.run(fn)', function () { - it('should emit "retryable fail" when a retryable test fails', function (done) { + describe('.run(fn)', function() { + it('should emit "retryable fail" 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 () { + var TEST = new Test('im a test about bears', function() { if (retryableFails < retries) { throw ERR; } @@ -401,7 +401,7 @@ describe('Runner', function() { suite.retries(retries); suite.addTest(TEST); - runner.on('retryable fail', function (test, err) { + runner.on('retryable fail', function(test, err) { retryableFails += 1; // retries clone the tests, so I guess comparing the test @@ -410,7 +410,7 @@ describe('Runner', function() { expect(err).to.equal(ERR); }); - runner.run(function (failures) { + runner.run(function(failures) { expect(failures).to.equal(0); expect(retryableFails).to.equal(retries); From 4883c5b1870bceb0fe859678d09cb03c9752a298 Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Thu, 17 May 2018 22:08:31 -0400 Subject: [PATCH 4/5] fixing expect statements --- test/unit/runner.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/runner.spec.js b/test/unit/runner.spec.js index 0ec0e3d187..f968c7bf2a 100644 --- a/test/unit/runner.spec.js +++ b/test/unit/runner.spec.js @@ -406,13 +406,13 @@ describe('Runner', function() { // retries clone the tests, so I guess comparing the test // names should be enough - expect(test.title).to.equal(TEST.title); - expect(err).to.equal(ERR); + expect(test.title, 'to be', TEST.title); + expect(err, 'to be', ERR); }); runner.run(function(failures) { - expect(failures).to.equal(0); - expect(retryableFails).to.equal(retries); + expect(failures, 'to be', 0); + expect(retryableFails, 'to be', retries); done(); }); From 7b29931e2cda14dbdcba562224f2fb116fdc3d77 Mon Sep 17 00:00:00 2001 From: Kiril Vatev Date: Sat, 19 May 2018 13:46:38 -0400 Subject: [PATCH 5/5] removing TEST.retries, as per review comments --- test/unit/runner.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/runner.spec.js b/test/unit/runner.spec.js index f968c7bf2a..1eea18b73b 100644 --- a/test/unit/runner.spec.js +++ b/test/unit/runner.spec.js @@ -397,7 +397,6 @@ describe('Runner', function() { } }); - TEST.retries(retries); suite.retries(retries); suite.addTest(TEST);