is there a way to run a file before the tests, like we can in mocha?
Closed this issue · 5 comments
I'm working on a sailsjs app and for API tests I do this in mocha
mocha test/test.upstart.js --recursive test/api
which executes test.upstart.js
before all the tests, running the setup code required for the SailsJS framework and my app. How would I do something like that with mocha-casperjs?
So you can do any setup you want outside of a test and describe
block that will run before the tests run, like
var myModule = require('my-module').doSomeStuff()
describe('Upstart', function() {
myModule.someMoreSetupThatRunsBeforeTests()
it('works', function() { ... })
})
Can this work for you?
Yep, that should work -- I was thinking of that as a workaround myself. Ideally there would be a way to make it so that every file didn't have to have the same line of code at the top, like mocha allow via command-line argument as shown above. Casper enables the same thing with -pre, so I thought it would make sense to expose it for mocha-casperjs.
Ok I see what you're doing. mocha-casperjs
works the same way - if you give it a bunch of files to load, it require
s them in that order. So this should work for you
mocha-casperjs test/test.upstart.js test/api/foo.js ...
There isn't a recursive option yet (tracking that in #20) so you'll have to specify them individually (or use globbing from zsh or something else)
@ultrasaurus Did that work for you?
@nathanboktae I found a different approach, but this is good to know. Thanks!