Ability to specify path for mocha.opts
Closed this issue · 4 comments
First, thanks for the great tool. It has proven incredibly useful in our grunt workflow.
My question is with respect to mocha.opts
. In an effort not to maintain options in two places, it would be ideal in our scenario to take advantage of mocha.opts
.
With the CLI, the --opts path can be provided, i.e.:
./node_modules/mocha/bin/mocha ./webserver/test/rspec --opts ./webserver/test/mocha.opts
Is there a way to provide this path option to the grunt.config
? I have tried all of the following:
config.mocha_istanbul = {
target: {
options: {
mochaOptions: ['--opts ./webserver/test/mocha.opts']
},
src: [...]
}
};
//----------------------//
config.mocha_istanbul = {
target: {
options: {
mochaOptions: ['--opts=./webserver/test/mocha.opts']
},
src: [...]
}
};
//----------------------//
config.mocha_istanbul = {
target: {
options: {
mochaOptions: ['--opts ' + require('path').resolve(__dirname, './webserver/test/mocha.opts')]
},
src: [...]
}
};
//----------------------//
config.mocha_istanbul = {
target: {
options: {
mochaOptions: ['--opts=' + require('path').resolve(__dirname, './webserver/test/mocha.opts')]
},
src: [...]
}
};
Any help would be greatly appreciated.
options and paths usually come separated
config.mocha_istanbul = {
target: {
options: {
mochaOptions: ['--opts','./webserver/test/mocha.opts']
},
src: [...]
}
};
although I'm not sure if a relative path will work, you may try using __dirname
and path.join
@pocesar - That did the trick!
Maybe worth noting that in other situations:
options: {
mochaOptions: ['--require=mocha-clean']
}
The =
separator works. This is what led to my initial confusion.
Also, worked with and without the path.resolve()
.
I really appreciate your quick response.
no problem. when there is the =
, it's considered 1 argument. when its --something anotherthing
it must be placed as another item in the array ['--something', 'anotherthing']
. that's because that's how child_process.spawn
passes the args down to the process, node docs are lackluster in this sense
Great information, I'll pass it on. Thanks again.