Skip to content

Instantly share code, notes, and snippets.

@hayes
Created May 13, 2014 21:20
Show Gist options
  • Save hayes/f6b5ea55c506c9f8b62c to your computer and use it in GitHub Desktop.
Save hayes/f6b5ea55c506c9f8b62c to your computer and use it in GitHub Desktop.
var tape = require('tape')
module.exports = setup
function setup(up, down, run) {
return function add_test(name, fn) {
var test_state = {}
var test = tape(name, function(t) {
test_state = up ? up(test_state) : test_state
fn.call(this, t, context)
})
})
test.on('end', function() {
if(down) {
down(test_state)
}
})
if(run) {
test.on('run', function() {
run(test_state)
})
}
return test
}
}
var setup = require('./setup')
var test = setup(up, down, run)
test('something', function(t, state) {
t.equal(state.setup, 'yup')
t.end()
})
function up(state) {
//called right after test is added
state.up = 'yup'
return state
}
function run(state) {
//callled when test is about to start
}
function down(state) {
//callled after the test ends
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment