diff --git a/lib/runner.js b/lib/runner.js index 6952efa92c..5e7a93dcc2 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -874,17 +874,13 @@ Runner.prototype.run = function(fn) { } self.started = true; if (self._delay) { - self.emit(constants.EVENT_DELAY_END); + self.emit(constants.EVENT_DELAY_END); } - Runner.immediately(function() { - self.emit(constants.EVENT_RUN_BEGIN); - }); + self.emit(constants.EVENT_RUN_BEGIN); self.runSuite(rootSuite, function() { debug('finished running'); - Runner.immediately(function() { - self.emit(constants.EVENT_RUN_END); - }); + self.emit(constants.EVENT_RUN_END); }); } diff --git a/test/integration/events.spec.js b/test/integration/events.spec.js index ef3aea7931..200c75e51e 100644 --- a/test/integration/events.spec.js +++ b/test/integration/events.spec.js @@ -75,4 +75,24 @@ describe('event order', function() { }); }); }); + + describe('--retries and --bail test case', function() { + it('should assert --retries event order', function(done) { + runMochaJSON( + 'runner/events-bail-retries.fixture.js', + ['--retries', '1', '--bail'], + function(err, res) { + if (err) { + done(err); + return; + } + expect(res, 'to have failed with error', 'error test A') + .and('to have failed test count', 1) + .and('to have passed test count', 0); + done(); + } + ); + }); + }); + }); diff --git a/test/integration/fixtures/runner/events-bail-retries.fixture.js b/test/integration/fixtures/runner/events-bail-retries.fixture.js new file mode 100644 index 0000000000..62c5f58bde --- /dev/null +++ b/test/integration/fixtures/runner/events-bail-retries.fixture.js @@ -0,0 +1,27 @@ +'use strict'; +var Runner = require('../../../../lib/runner.js'); +var assert = require('assert'); + +var emitOrder = [ + 'start', 'suite', 'suite', + 'hook', 'hook end', 'test', 'hook', 'hook end', 'retry', 'hook', 'hook end', + 'test', 'hook', 'hook end', 'fail', 'test end', 'hook', 'hook end', 'hook', 'hook end', + 'suite end', 'suite end', 'end' +]; + +var realEmit = Runner.prototype.emit; +Runner.prototype.emit = function(event, ...args) { + // console.log(`emit: ${event}`); + assert.strictEqual(event, emitOrder.shift()); + return realEmit.call(this, event, ...args); +}; + +describe('suite A', function() { + before('before', function() {}); + beforeEach('beforeEach', function() {}); + it('test A', function() { + throw new Error('error test A'); + }); + afterEach('afterEach', function() {}); + after('after', function() {}); +}); diff --git a/test/integration/fixtures/runner/events-bail.fixture.js b/test/integration/fixtures/runner/events-bail.fixture.js index 7b060bd43c..ccb54a0631 100644 --- a/test/integration/fixtures/runner/events-bail.fixture.js +++ b/test/integration/fixtures/runner/events-bail.fixture.js @@ -13,9 +13,9 @@ var EVENT_TEST_END = constants.EVENT_TEST_END; var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL; var emitOrder = [ - EVENT_SUITE_BEGIN, // incorrect order EVENT_RUN_BEGIN, EVENT_SUITE_BEGIN, + EVENT_SUITE_BEGIN, EVENT_HOOK_BEGIN, EVENT_HOOK_END, EVENT_TEST_BEGIN, diff --git a/test/integration/fixtures/runner/events-basic.fixture.js b/test/integration/fixtures/runner/events-basic.fixture.js index 7a352379ec..6f38878c17 100644 --- a/test/integration/fixtures/runner/events-basic.fixture.js +++ b/test/integration/fixtures/runner/events-basic.fixture.js @@ -18,9 +18,9 @@ var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING; var EVENT_TEST_RETRY = constants.EVENT_TEST_RETRY; var emitOrder = [ - EVENT_SUITE_BEGIN, // incorrect order EVENT_RUN_BEGIN, EVENT_SUITE_BEGIN, + EVENT_SUITE_BEGIN, EVENT_HOOK_BEGIN, EVENT_HOOK_END, EVENT_TEST_BEGIN, diff --git a/test/integration/fixtures/runner/events-delay.fixture.js b/test/integration/fixtures/runner/events-delay.fixture.js index 9a50760884..b1ac40ff30 100644 --- a/test/integration/fixtures/runner/events-delay.fixture.js +++ b/test/integration/fixtures/runner/events-delay.fixture.js @@ -20,9 +20,9 @@ var EVENT_TEST_RETRY = constants.EVENT_TEST_RETRY; var emitOrder = [ EVENT_DELAY_BEGIN, EVENT_DELAY_END, - EVENT_SUITE_BEGIN, // incorrect order EVENT_RUN_BEGIN, EVENT_SUITE_BEGIN, + EVENT_SUITE_BEGIN, EVENT_HOOK_BEGIN, EVENT_HOOK_END, EVENT_TEST_BEGIN, diff --git a/test/integration/fixtures/runner/events-retries.fixture.js b/test/integration/fixtures/runner/events-retries.fixture.js index f8936aebfa..987c3d8162 100644 --- a/test/integration/fixtures/runner/events-retries.fixture.js +++ b/test/integration/fixtures/runner/events-retries.fixture.js @@ -14,9 +14,9 @@ var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL; var EVENT_TEST_RETRY = constants.EVENT_TEST_RETRY; var emitOrder = [ - EVENT_SUITE_BEGIN, // incorrect order EVENT_RUN_BEGIN, EVENT_SUITE_BEGIN, + EVENT_SUITE_BEGIN, EVENT_HOOK_BEGIN, EVENT_HOOK_END, EVENT_TEST_BEGIN,