Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent subsequent hooks from being called if we are --bailing. #835

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e4a4744
adding before hook to --bail test
aearly May 4, 2013
3f2d701
prevent hooks from being called if we are bailing
aearly May 5, 2013
e45b52f
added complicated bail test
aearly May 5, 2013
d72dd5c
augmented bail test
aearly May 5, 2013
f307c88
fine-grained bailing working
aearly May 5, 2013
48224f9
initial parallel prototype
aearly May 8, 2013
0a05d96
working on parallelism
aearly May 9, 2013
633ae91
made bailing suites still call hooks if they were the source of the e…
aearly May 9, 2013
9782562
made bailing suites still call hooks if they were the source of the e…
aearly May 9, 2013
2f68097
breaking in the runner to see what assumptions it is making
aearly May 12, 2013
ca8e030
running suites in child runner objects
aearly May 12, 2013
c3b6f5b
changing hookUp and hookDown to use runners
aearly May 12, 2013
6f5b12f
working on runner end
aearly May 13, 2013
0e804f2
trying to fix globals
aearly May 13, 2013
3b8a9b5
fixed global detection
aearly May 13, 2013
ad656e4
refactored runSuites to use an eachSeries method
aearly May 13, 2013
521e4fa
added .jshinrc
aearly May 13, 2013
9792d45
refactored runSuite to use eachParallel when suite._parallel == true
aearly May 13, 2013
bc97cc3
working test for parallel suites
aearly May 13, 2013
ca7826e
fixed ordering of events for parallel reporting
aearly May 13, 2013
c97216b
parallel failing working, as well as bailing
aearly May 14, 2013
4f12a5e
merge from feature branch
aearly May 14, 2013
d593e38
made fails more specific
aearly May 15, 2013
30b26a7
fixed pending tests
aearly May 15, 2013
f5c0d95
Merge branch 'feature/parallel-suites'
aearly May 15, 2013
0f4eb7b
adding --parallel CLI option
aearly May 16, 2013
e1e88ba
fixed parallel reporting with child suites
aearly May 16, 2013
fe730b7
cleaned up the api, added .parallel() accessor to Suite
aearly May 16, 2013
00a57ff
merge from feature branch
aearly May 16, 2013
e3735bb
removing extraneous debugger statement
aearly May 17, 2013
a61ab0b
Update Readme with new CI image.
aearly May 17, 2013
94d9e48
fixed exit code always being 0, regardless of failures
aearly May 20, 2013
fc9e6c0
made parallel suites run in domains (and made them a node-only feature)
aearly May 20, 2013
fb6b902
Merge branch 'feature/parallel-suites'
aearly May 20, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleaned up the api, added .parallel() accessor to Suite
  • Loading branch information
aearly committed May 16, 2013
commit fe730b7338c97c2728c52ec4d3810537915ceb9a
2 changes: 1 addition & 1 deletion bin/_mocha
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ if (program.asyncOnly) mocha.asyncOnly();

// --parallel

if (program.parallel) mocha.parallel(true);
if (program.parallel) mocha.parallel();

// --globals

Expand Down
4 changes: 2 additions & 2 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ Mocha.prototype.asyncOnly = function(){
};

/**
* Makes root-suites run in parallel
* Makes root-level suites run in parallel
*
* @return {Mocha}
* @api public
Expand All @@ -321,7 +321,7 @@ Mocha.prototype.run = function(fn){
var reporter = new this._reporter(runner);
runner.ignoreLeaks = false !== options.ignoreLeaks;
runner.asyncOnly = options.asyncOnly;
runner.suite._parallel = options.parallel;
runner.suite.parallel(options.parallel);
if (options.grep) runner.grep(options.grep, options.invert);
if (options.globals) runner.globals(options.globals);
if (options.growl) this._growl(runner, reporter);
Expand Down
28 changes: 14 additions & 14 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Runner.prototype.hook = function(name, fn){
, self = this
, timer;

// if we're bailing, only run hooks if this.suite cause it, otherwise, skip
// if we're bailing, only run hooks if this suite caused it, otherwise, skip
if (suite.failures && suite.bail() && !suite.failSource) return fn();

function next(i) {
Expand Down Expand Up @@ -448,21 +448,19 @@ Runner.prototype.runSuite = function(suite, fn){

function done() {
debug('suite done %s', suite.fullTitle());
//self.suite = runner.suite;

self.hook('afterAll', function(){
debug('suite end %s', suite.fullTitle());
if (self.suite._parallel) {
runners.forEach(function (runner) {
self._rebroadcastAll(runner);
})
if (suite.parallel()) {
self._rebroadcastAll(runners);
}
self.emit('suite end', suite);
fn();
});
}

function next() {
if (suite._parallel) {
if (suite.parallel()) {
utils.eachParallel(suite.suites, suiteItr, done);
} else {
utils.eachSeries(suite.suites, suiteItr, done);
Expand Down Expand Up @@ -501,7 +499,7 @@ Runner.prototype._wrapEvents = function(runner) {
runner.eventCache = [];
_events.forEach(function (event) {
runner.on(event, function (data, err) {
if (self.suite._parallel) {
if (self.suite.parallel()) {
runner.eventCache.push({event: event, data: data, err: err});
} else {
self.emit(event, data, err);
Expand All @@ -511,15 +509,17 @@ Runner.prototype._wrapEvents = function(runner) {
};

/**
* Replay the cached events from a child runner as if this runner emitted them
* @param {Runner} runner
* Replay the cached events from child runners as if this runner emitted them
* @param {Array[Runner]} runners
* @api private
*/
Runner.prototype._rebroadcastAll = function (runner) {
Runner.prototype._rebroadcastAll = function (runners) {
var self = this;
runner.eventCache.forEach(function (cache) {
self.emit(cache.event, cache.data, cache.err);
});
runners.forEach(function (runner) {
runner.eventCache.forEach(function (cache) {
self.emit(cache.event, cache.data, cache.err);
});
})
};

/**
Expand Down
15 changes: 15 additions & 0 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ Suite.prototype.bail = function(bail){
return this;
};

/**
* Sets whether to run child suites in parallel
*
* @param {Boolean} parallel
* @return {Suite|Number} for chaining
* @api private
*/

Suite.prototype.parallel = function(parallel){
if (0 == arguments.length) return this._parallel;
debug('parallel %s', parallel);
this._parallel = parallel;
return this;
};

/**
* Mark this suite as having failures, as well as any child suites.
* This is bookkeeping for fine-grained bailing.
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/misc/parallelFail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('parallel failing', function () {

this._parallel = true;
this.parallel(true);
var runs = 0;

after(function (done) {
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/parallel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('parallel suite', function () {
var start;

this._parallel = true;
this.parallel(true);

before(function (done) {
start = new Date();
Expand Down