Browse files

passing context & executing setup

  • Loading branch information...
1 parent 771b85a commit e035cdc67dc7cfccb3e7d14ce1fb46e316321762 @brianc committed Dec 21, 2010
Showing with 49 additions and 5 deletions.
  1. +20 −5 lib/index.js
  2. +29 −0 test/initial-tests.js
View
25 lib/index.js
@@ -1,16 +1,31 @@
var executeAction = function(action, callback) {
var i = 0
- var doAction = function(action) {
+ var doAction = function(action, context) {
//no more repeats to execute
if(action.repeat > i++) {
- action.run(function() {
- doAction(action)
- })
+ if(context) {
+ var cb = function() {
+ doAction(action, context)
+ }
+ action.run(context, cb)
+ } else {
+ var cb = function() {
+ doAction(action)
+ }
+ action.run(cb)
+ }
} else {
callback();
}
}
- doAction(action)
+ if(action.setup) {
+ action.setup(function(result) {
+ doAction(action, result)
+ })
+ } else {
+ doAction(action)
+ }
+
}
var bench = function(config) {
View
29 test/initial-tests.js
@@ -85,3 +85,32 @@ test('multiple actions', function() {
})
})
+
+test('action setup', function() {
+ test('not passing setup arg to following contexts', function() {
+ var boom = 0;
+ var bm = bench({
+ repeat: 10,
+ actions:[{
+ name: 'boom',
+ setup: function(next) {
+ next(++boom)
+ },
+ run: function(context, next) {
+ context.should.equal(1)
+ next()
+ },
+ teardown: function(context, next) {
+ arg.should.equal(1)
+ next()
+ }
+ }]
+ })
+ bm(should.call(function() {
+ test('executes', function() {
+ boom.should.equal(1)
+ })
+
+ }))
+ })
+})

0 comments on commit e035cdc

Please sign in to comment.