Tests: Unbreak test:cli due to unknown 'qunit' command #1339
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follows-up 362e241, which removed 'npm link' from the 'test:cli'
script command.
Initially, I thought the reason the child processes can't find qunit is due to our use of
execa.shell
instead of regularexeca
. Specifically,execa.shell()
spawns a process that starts with a new shell and no inherited environment variables.execa()
on the other hand inherits environment variables like PATH by default, and it also has apreferLocal
option that ensures node_modules/.bin is in thePATH
even if you're running the tests withoutnpm run ..
(e.g. if you'd usebin/qunit test/cli/*.js
directly).Switching to
execa()
is non-trivial because it requires an array as input and there aren't built-in or trust-worthy modules that parse a command string into an array. Trying it with brute-force I realised the problem is actually thatqunit
isn't visible at all even in the original environment created by npm-run.While npm-run does add node_modules/.bin, and bins from (dev)dependencies are indeed linked from there, the bins from the current package itself (qunit) are never linked in .bin.
So... keeping it simple and just string-replacing 'qunit' with 'bin/qunit', which also matches the way we invoke the cli from other commands in package.json already.