How to run cleanup with vows.js?
Asked Answered
M

3

8

I'm using Vows.js to test some node.js which is creating records in a database. As a result of this it creates some test records in the database. I'd like to remove these records once the tests have run. Is there a way to run a cleanup function when a batch of tests is run in Vows?

Menhaden answered 15/8, 2011 at 12:43 Comment(0)
V
14

You can define the teardown function in your context that is executed once all the tests in your context are run.

vows.describe('Foo').addBatch({
    'A Context' : {
       topic : { foo: 'bar' },
       'it works' : function (topic) { assert.equal(topic.foo, "bar"); },
       teardown : function (topic) { topic.foo = "baz" }
    }
});

You can see this in Vows own tests.

Vest answered 15/8, 2011 at 18:14 Comment(0)
D
2

If it were me, I would use a separate test database when running automated tests, and empty that database before each test run.

Dufour answered 15/8, 2011 at 16:53 Comment(0)
M
0

There's an open pull request for vows implementing afterSuite:

https://github.com/phstc/vows/commit/d5b40e85e924e06cca560b4d8d6a264528bbab2b

Madelainemadeleine answered 23/1, 2013 at 12:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.