I know about before
, beforeEach
, after
and afterEach
but how do I run some code before ALL tests.
In other words I files like this
test
test1.js
test2.js
test3.js
I run the tests with
mocha --recursive
I don't want to have to put a before
in every test file. I need a beforeAllTests
or a --init=setup.js
or something that I can execute some JavaScript before any tests have been executed. In this particular case I have to configure my system's logging module before the tests run
Is there a way to call some init function that get executed before all tests?
If only initialization code is required, then mocha -r ./init
might be enough for you. even put it into test/mocha.opts
--require ./test/init
--ui tdd
But if you need teardown actions, there is a dilemma, for example:
var app = require('../app.js');
app.listen(process.env.WEB_PORT);
after(function(done) {
var db = mongoskin.db(process.env.DB_URL, {safe:true});
db.dropDatabase(function(err) {
expect(err).to.not.be.ok();
db.close(done);
});
});
you'll get the error:
ReferenceError: after is not defined
I guess mocha hasn't been initialized itself while handling '--require'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With