Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
micellius opened this issue Oct 7, 2014 · 9 comments

Comments

@micellius
Copy link

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
Copy link
Contributor

kof commented Oct 7, 2014

Have you tried process.env in the child?

@kof
Copy link
Contributor

kof commented Oct 7, 2014

@kof
Copy link
Contributor

kof commented Oct 7, 2014

If it doesn't work, any ideas?

@micellius
Copy link
Author

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
Copy link
Contributor

kof commented Oct 7, 2014

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
Copy link
Contributor

kof commented Oct 7, 2014

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

kof added a commit that referenced this issue Oct 7, 2014
@kof
Copy link
Contributor

kof commented Oct 7, 2014

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

@kof
Copy link
Contributor

kof commented Oct 7, 2014

check it out, reopen if something is wrong.

@kof kof closed this as completed Oct 7, 2014
@kof kof mentioned this issue Oct 7, 2014
@micellius
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants