Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

It drove me nuts.

It turned out that previously implemented `setup` and `teardown` are
actually `startup` and `shutdown`. Do I need a good rest or something?
  • Loading branch information...
commit a41779ea3e8eea0fe1846058bb20eb44478cefe1 1 parent 677e539
@5long authored
Showing with 42 additions and 4 deletions.
  1. +8 −0 src/suite_monad.js
  2. +34 −4 src/test_suite.js
View
8 src/suite_monad.js
@@ -18,6 +18,14 @@ util.merge(SuiteMonad.prototype, {
this._suite.addTeardown(fn)
return this
}
+, startup: function(fn) {
+ this._suite.addStartup(fn)
+ return this
+ }
+, shutdown: function(fn) {
+ this._suite.addShutdown(fn)
+ return this
+ }
})
module.exports = SuiteMonad
View
38 src/test_suite.js
@@ -6,6 +6,8 @@ function TestSuite(desc) {
this.desc = desc
this._setupQueue = []
this._teardownQueue = []
+ this._startupQueue = []
+ this._shutdownQueue = []
this._tests = []
}
util.inherits(TestSuite, EventEmitter)
@@ -19,19 +21,18 @@ util.merge(TestSuite.prototype, {
}
async.chain(
function setup() {
- thisSuite._doSetup(conf.fixture, this)
+ thisSuite._doStartup(conf.fixture, this)
}
, function test(err) {
if (err) throw err
thisSuite.emit("start")
async.map(thisSuite._tests, function(t) {
- thisSuite.emit("yield", t)
- t.run(conf, this)
+ thisSuite._runTest(t, conf, this)
}, this)
}
, function teardown(err, results) {
if (err) return this(err, [])
- thisSuite._doTeardown(conf.fixture, this)
+ thisSuite._doShutdown(conf.fixture, this)
}
, function end(err, dummy, results) {
thisSuite.emit("end")
@@ -49,6 +50,35 @@ util.merge(TestSuite.prototype, {
fn(fixture, this)
}, cb)
}
+, _doStartup: function(fixture, cb) {
+ async.paraMap(this._startupQueue, function(fn) {
+ fn(fixture, this)
+ }, cb)
+ }
+, _doShutdown: function(fixture, cb) {
+ async.paraMap(this._startupQueue, function(fn) {
+ fn(fixture, this)
+ }, cb)
+ }
+, _runTest: function(t, conf, cb) {
+ var thisSuite = this
+ async.chain(
+ function setup() {
+ thisSuite._doSetup(conf.fixture, this)
+ }
+ , function run(err) {
+ thisSuite.emit("yield", t)
+ t.run(conf, this)
+ }
+ , function(err, result) {
+ if (err) return this(err, result)
+ thisSuite._doTeardown(conf.fixture, this)
+ }
+ , function(err, dummy, result) {
+ cb(err, result)
+ }
+ )
+ }
, add: function(test) {
this._tests.push(test)
}
Please sign in to comment.
Something went wrong with that request. Please try again.