|
|
@ -4,6 +4,8 @@ var EventEmitter = require('events').EventEmitter; |
|
|
|
var Promise = require('bluebird'); |
|
|
|
var Test = require('./test'); |
|
|
|
|
|
|
|
function noop() {} |
|
|
|
|
|
|
|
function each(items, fn) { |
|
|
|
return Promise.all(items.map(fn)); |
|
|
|
} |
|
|
@ -71,7 +73,7 @@ Runner.prototype.addAfterEachHook = function (title, cb) { |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
Runner.prototype._runTest = function (test) { |
|
|
|
Runner.prototype._runTestWithHooks = function (test) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var beforeHooks = self.tests.beforeEach.map(function (hook) { |
|
|
@ -88,22 +90,26 @@ Runner.prototype._runTest = function (test) { |
|
|
|
tests.push(test); |
|
|
|
tests.push.apply(tests, afterHooks); |
|
|
|
|
|
|
|
return eachSeries(tests, function (test) { |
|
|
|
// add test result regardless of state
|
|
|
|
// but on error, don't execute next tests
|
|
|
|
return test.run() |
|
|
|
.finally(function () { |
|
|
|
self._addTestResult(test); |
|
|
|
}); |
|
|
|
}).catch(function () {}); |
|
|
|
return eachSeries(tests, this._runTest.bind(this)).catch(noop); |
|
|
|
}; |
|
|
|
|
|
|
|
Runner.prototype._runTest = function (test) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
// add test result regardless of state
|
|
|
|
// but on error, don't execute next tests
|
|
|
|
return test.run() |
|
|
|
.finally(function () { |
|
|
|
self._addTestResult(test); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
Runner.prototype.concurrent = function (tests) { |
|
|
|
return each(tests, this._runTest.bind(this)); |
|
|
|
return each(tests, this._runTestWithHooks.bind(this)); |
|
|
|
}; |
|
|
|
|
|
|
|
Runner.prototype.serial = function (tests) { |
|
|
|
return eachSeries(tests, this._runTest.bind(this)); |
|
|
|
return eachSeries(tests, this._runTestWithHooks.bind(this)); |
|
|
|
}; |
|
|
|
|
|
|
|
Runner.prototype._addTestResult = function (test) { |
|
|
@ -125,7 +131,8 @@ Runner.prototype.run = function () { |
|
|
|
var tests = this.tests; |
|
|
|
var stats = this.stats; |
|
|
|
|
|
|
|
return this.serial(tests.before) |
|
|
|
return eachSeries(tests.before, this._runTest.bind(this)) |
|
|
|
.catch(noop) |
|
|
|
.then(function () { |
|
|
|
if (stats.failCount > 0) { |
|
|
|
return Promise.reject(); |
|
|
@ -138,11 +145,9 @@ Runner.prototype.run = function () { |
|
|
|
return self.concurrent(tests.concurrent); |
|
|
|
}) |
|
|
|
.then(function () { |
|
|
|
return self.serial(tests.after); |
|
|
|
}) |
|
|
|
.catch(function () { |
|
|
|
return; |
|
|
|
return eachSeries(tests.after, self._runTest.bind(self)); |
|
|
|
}) |
|
|
|
.catch(noop) |
|
|
|
.then(function () { |
|
|
|
stats.passCount = stats.testCount - stats.failCount; |
|
|
|
}); |
|
|
|