Skip to content

Commit

Permalink
Revert 00ca06b; closes #3414
Browse files Browse the repository at this point in the history
- Updates events test to match correct event order
- Add test for retries-and-bail case
  • Loading branch information
boneskull committed Feb 4, 2019
1 parent e01a54e commit b460f6a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 13 deletions.
9 changes: 2 additions & 7 deletions lib/runner.js
Expand Up @@ -857,15 +857,10 @@ Runner.prototype.run = function(fn) {
filterOnly(rootSuite);
}
self.started = true;
Runner.immediately(function() {
self.emit('start');
});

self.emit('start');
self.runSuite(rootSuite, function() {
debug('finished running');
Runner.immediately(function() {
self.emit('end');
});
self.emit('end');
});
}

Expand Down
19 changes: 19 additions & 0 deletions test/integration/events.spec.js
Expand Up @@ -56,4 +56,23 @@ 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();
}
);
});
});
});
27 changes: 27 additions & 0 deletions 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() {});
});
4 changes: 2 additions & 2 deletions test/integration/fixtures/runner/events-bail.fixture.js
Expand Up @@ -3,14 +3,14 @@ var Runner = require('../../../../lib/runner.js');
var assert = require('assert');

var emitOrder = [
'suite'/* incorrect order*/, 'start', 'suite',
'start', 'suite', 'suite',
'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}`);
// console.log(`emit: ${event}`);
assert.strictEqual(event, emitOrder.shift());
return realEmit.call(this, event, ...args);
};
Expand Down
3 changes: 1 addition & 2 deletions test/integration/fixtures/runner/events-basic.fixture.js
Expand Up @@ -3,15 +3,14 @@ var Runner = require('../../../../lib/runner.js');
var assert = require('assert');

var emitOrder = [
'suite'/* incorrect order*/, 'start', 'suite',
'start', 'suite', 'suite',
'hook', 'hook end', 'test', 'hook', 'hook end', 'pass', 'test end', 'hook', 'hook end',
'suite', 'test', 'hook', 'hook end', 'pass', 'test end', 'hook', 'hook end',
'suite 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);
};
Expand Down
4 changes: 2 additions & 2 deletions test/integration/fixtures/runner/events-retries.fixture.js
Expand Up @@ -3,15 +3,15 @@ var Runner = require('../../../../lib/runner.js');
var assert = require('assert');

var emitOrder = [
'suite'/* incorrect order*/, 'start', 'suite',
'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}`);
// console.log(`emit: ${event}`);
assert.strictEqual(event, emitOrder.shift());
return realEmit.call(this, event, ...args);
};
Expand Down

0 comments on commit b460f6a

Please sign in to comment.