azer / prova

Test runner based on Tape and Browserify
Other
333 stars 30 forks source link

Include setup/teardown via wrapping-tape or similar #25

Open knownasilya opened 10 years ago

knownasilya commented 10 years ago

https://www.npmjs.org/package/wrapping-tape

Looks like a nice way to add setup/teardown functionality to tape, would be nice to have this baked into prova.

azer commented 10 years ago

sorry, prova wouldn't have this kind of extras since it follows the same simplicity goal with tape and we wanna keep it compatible.

I'd recommend to just use functions. e.g

test("foo", function () {
  setup()
  teardown()
})

function setup () {}
function teardown () {}
knownasilya commented 10 years ago

@azer so how would I have the teardown function run after the test finishes? Is there a way to hook into t.end or t.plan?

azer commented 10 years ago

there are lots of ways, for example;

test("foo", finish(function (assert) {
  assert.plan(1)
  assert.equal(3.14, 3.14)
})

function finish (fn) {
  return function (assert) {
    fn()
    teardown()
    otherstuff()
  }
})
knownasilya commented 10 years ago

@azer ah, the obvious solution :+1:

azer commented 10 years ago

let me know your experience. it may be getting more complex once you need your teardown to be async, etc. we can keep using this issue as a place for improving the experience and sharing solutions, so I'm reopening...