Wrong node binary picked up to process tests
- Version: 7.2.0
- Platform: linux x86_64
When running c8 with mocha for example, as such: node node_modules/c8/bin/c8 node_modules/mocha/bin/mocha test.js, it is not guaranty that the same node binary will be used to process c8 and mocha (and therefore the test), is this intended?
This is coming from this piece of code: https://github.com/bcoe/c8/blob/master/lib/parse-args.js#L131
if (argv[0][0] === '-') {
argv.unshift(process.execPath)
}
The node executable is only added if the first argument not parsed is an option. Why not doing it all the time?
In my case, I am using various node versions for my unit tests. And it might pick up the version in /usr/bin unless specially specified like this: node node_modules/c8/bin/c8 node node_modules/mocha/bin/mocha test.js
To me, this seems redundant and not intuitive. The current behavior might lead to unexpected issues that might be hard to spot.
@blaizard I tend to run c8 as a bin itself, assuming that it will use the version of Node configured in the shebang:
#!/usr/bin/env node
So I would tend to write things more like:
c8 mocha test.js
Both c8 and mocha are executables, and will use the system version of node, so shouldn't need the node prefix to execute them.
I'm not shocked that node node_modules/c8/bin/c8 node node_modules/mocha/bin/mocha test.js could potentially lead to a discrepancy in the version of Node.js being used ... at the same time, I question whether it's worth fix, it seems like optimizing to use the system version of Node.js is a reasonable decision?
I agree and this is the most common way and expected way of using node tools. However, my issue rose because of my testing setup. I am using a sandboxed environment with bazel and pull automatically from the web, the node toolchain I am testing against. However, I also have node installed locally. Since I call all the tests explicitly with the node binary I want to use, I was expecting that c8 will just propagate the same binary to execute mocha. I don't think it is an issue and it is just the way the tool is designed. But we should at least point this out in the documentation, at least for me it was not obvious (that in my case) another node binary would be used.
@blaizard if we could figure out a way to test this, perhaps with a fake node bin and using child_process, I would be open to trying to make c8 more clever about picking the right bin. I just want to be mindful that we have a test around the logic, as I'm imagining it being finicky.