Skip to content

Commit

Permalink
Tests: Unbreak test:cli due to unknown 'qunit' command
Browse files Browse the repository at this point in the history
Follows-up 362e241, which removed 'npm link' from the 'test:cli'
script command.

Initially, I thought the reason the child proceses can't find qunit
is due to our use of execa.shell instead of regular execa. 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 a
'preferLocal' option that ensures node_modules/.bin is in the PATH
even if you're running the tests without 'npm run ..' (e.g. if you'd
use 'bin/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 that 'qunit' 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.
  • Loading branch information
Krinkle committed Dec 18, 2018
1 parent 62374ea commit 474a158
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions test/cli/helpers/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = function execute( command ) {
const cwd = process.cwd();
process.chdir( path.join( __dirname, "..", "fixtures" ) );

command = command.replace( /^qunit\b/, "../../../bin/qunit" );
const execution = exec( command );

process.chdir( cwd );
Expand Down

0 comments on commit 474a158

Please sign in to comment.