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: pass flags to io.js / node #160

Closed
yoshuawuyts opened this issue Aug 17, 2015 · 9 comments
Closed

Feature request: pass flags to io.js / node #160

yoshuawuyts opened this issue Aug 17, 2015 · 9 comments

Comments

@yoshuawuyts
Copy link

io.js allows flags to be passed in on startup, of which the most interesting one for me is -r <package>.
With tape it's possible to do node -r 'babel/register' test, it'd be nice if there was a similar way to do that with tap.

E.g. maybe something like:

tap --flags '-r \'babel/register\'' **/test.js

Is this something that's desirable?

edit: Alternatively the -r, --require flag could be added but that seems less flexible / future proof than having direct access to the node process.

@yoshuawuyts
Copy link
Author

I think that if this feature was implemented, the following flags could be deprecated / turned into a convenience wrapper:

  --debug                     Run JavaScript tests with node --debug

  --debug-brk                 Run JavaScript tests with node --debug-brk

  --harmony                   Enable all Harmony flags in JavaScript tests

  --strict                    Run JS tests in 'use strict' mode

@tmcw
Copy link
Contributor

tmcw commented Dec 17, 2015

👍 right now running nyc with its --register option around tap that bundles a different version of nyc is pretty awkward, one true tool would be more predictable.

@isaacs
Copy link
Member

isaacs commented Dec 31, 2015

I'm ok with this in principle, and would definitely like to be able to pass both node-flags and nyc-flags.

However, the implementation in #193 of just splitting the arg on ' ' is a bit wierd. Consider: --flags='-r "/path with spaces/module.js"' or --flags='--many spaces'. In both cases, you'll get some positional arguments that don't make a lot of sense.

I'm wary of alternatives that involve implementing sh-compatible argument parsing of argument values, though! In general, passing a list of args as a single string is a bad smell, because it effectively requires that you exec() the command as an argument to a shell, rather than just spawning it directly.

Another idea, however, is to just have each flag be something that can be specified as a separate arg. For example:

tap test/*.js --nodeflag=-r --nodeflag=babel/register --nodeflag=--harmony --nodeflag=--use_strict --nodeflag=--expose_gc

It's a bit more tedious, but then it can just push each entry onto the flags list, rather than have to parse the string (and wow, you've got quotes in there... just... omg, I'm having an allergic reaction–been down that road too many times!)

Maybe the tediousness could be reduced with a shorthand option? Like -F-r -Fbabel/register -F--harmony -F--use_strict -F--expose_gc?

@yoshuawuyts
Copy link
Author

-F-r -Fbabel/register -F--harmony -F--use_strict -F--expose_gc

seems reasonable; reckon most of this is scripted once for a test script and then never looked at again so a bit of an odd interface shouldn't matter. I like it.

@isaacs
Copy link
Member

isaacs commented Dec 31, 2015

Cool. That's a lot easier to do, and requires zero extra parsing. The code in bin/run.js has shifted around a lot, but it should be pretty easy to write a patch for this. just options.nodeArgs.push(val) when you find a --node-flag arg.

Maybe we should have this for nyc, too? The latest versions have added some cool support for caching, babel stuff, etc.

@isaacs
Copy link
Member

isaacs commented Dec 31, 2015

If you don't feel like writing a patch, I may get to it probably this or next weekend.

@yoshuawuyts
Copy link
Author

I'm churning through a backlog of my own projects atm, this isn't blocking for me so someone else writing the patch would be preferable

@isaacs
Copy link
Member

isaacs commented Jan 20, 2016

Did this as --node-arg=--blerg which can be specified multiple times to provide multiple args, like tap --node-arg=--strict --node-arg=--expose_gc --node-arg=-r --node-arg=babel

@isaacs isaacs closed this as completed Jan 20, 2016
@yoshuawuyts
Copy link
Author

awesome! ✨

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

Successfully merging a pull request may close this issue.

3 participants