qunitjs/node-qunit

[Feature Request] Propagation of command line arguments to child processes required

Closed this issue · 9 comments

Using node-qunit for integration tests scenarios requires passing configuration options via command line to tests (like back-end host, etc.). Since test runner spawns new processes (child.js), process.argv of the parent process is no longer available in tests (because each spawened process has it's own process.argv). This issue may be solved by propagating command line arguments (passed to cli.js) to child processes via process.env and used as follows:

shell

$ ./node_modules/qunit/bin/cli.js -c src/code.js -t test/test.js --host test.domain.com

test.js

var host = process.env['qunit.args.host']; // <-- will be "test.domain.com"

For example jasmine-node allows to propagate command line arguments passed to cli.js using --config argument_name argument_value syntax.

kof commented

Have you tried process.env in the child?

kof commented

If it doesn't work, any ideas?

I have seen that you pass process.env in the child process, but it does not contain command line arguments out of the box, so I utilised this existing mechanism and submitted PR #106 to resolve the issue with minimum changes.

kof commented

http://nodejs.org/docs/latest/api/child_process.html#child_process_child_process_spawn_command_args_options

If I understand correctly the documentation, passed env object should be accessible in the child as it is in the parent, no?

kof commented

Oh its process.argv, not process.env.argv ...

kof commented

I have a better solution for this. Now you can use process.argv in the child.

kof commented

check it out, reopen if something is wrong.

Yes, you understand correctly: passed env is accessible in the child as in the parent, however in order to receive command line arguments of parent process you need process.argv or something that is called args in cli.js. Since cli.js passes to test runner only limited set of arguments it is familiar with (code, tests, deps and log), other arguments are lost and are not propagated further and therefore not accessible via process.argv or process.env of the child process. To solve this, I placed process.argv arguments one by one into process.env (which is already accessible in the child process) with qunit.args. prefix.