Is it possible to add extra params that are passed to the code executed
Closed this issue · 5 comments
Sometimes we need to pass some extra command line params to code executed.
As of now we have:
- nodeOptions
- mochaOptions
- istanbulOptions
none of them helps to achieve this goal.
Correct me if I'm wrong, but there's no possibility to add parameters at the and of args passed for execution. In other words, one cannot achieve something like this:
node_modules/istanbul/lib/cli.js cover --dir <some-dir> /node_modules/mocha/bin/_mocha -- target/test/specs/**/*.spec.js --some-extra-param
If I'm wrong and it's possible I'll be very much obliged if you'll show how it can be done.
If it is not, I suggest to add extraOptions (or whatever it will be named).
I can contribute.
what is the use case that a combination of the 3 options doesn't cover? --some-extra-param
wouldn't work in any case, even outside this plugin, mocha would 'swallow' it, even if you execute it in your command line.
when running tests, you won't actually run your files, if you need to change behavior inside your program, use environment variables. unless your project is a command line application, then you'll need to manually fill the process.argv
My use case is pretty much following, I have a bunyan logger which is initialized like this
const log = bunyan.createLogger({
name: 'app',
streams: [
{
level: argv['log-level'] || 'trace',
stream: ...
}
]
});
This logger is used throughout the whole codebase.
If I won't have an opportunity to pass command line param to the application itself
life is getting a bit more complicating than it seems it can be. I'm not sure that manually filling process.argv (what I've never tried to do to be honest) is a better way.
you could do that to use an environment variable like process.env['LOG_LEVEL'] || true
. process.argv
is an array, so that wouldn't work the way you have it in your code.
your entrypoint (aka your package.json main
field) is never called directly when using unit testing, unless you spawn a separated process that your tests will interact with them.
npm start
isn't the same as having your entrypoint require'd in your test files, so you can't actually pass in process arguments to your application unless you can control it from outside (like using environment variables, which is always the best choice for testing multiple behaviors internally)
OK, thank you for the response, I've forked project and added extraParams options, sometimes it's just something you need. Well, I need. I'm aware of workarounds as well of limitations but I clearly can see when this is needed.
alright!