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 authored and trentmwillis committed Dec 21, 2018
1 parent 62374ea commit b385b83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
7 changes: 5 additions & 2 deletions test/cli/helpers/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ const path = require( "path" );
const exec = require( "execa" ).shell;

// Executes the provided command from within the fixtures directory
module.exports = function execute( command ) {
// The execaOptions parameter is used by test/cli/watch.js to
// control the stdio stream.
module.exports = function execute( command, execaOptions ) {
const cwd = process.cwd();
process.chdir( path.join( __dirname, "..", "fixtures" ) );

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

process.chdir( cwd );

Expand Down
11 changes: 2 additions & 9 deletions test/cli/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@

const fs = require( "fs-extra" );
const path = require( "path" );
const exec = require( "execa" ).shell;
const co = require( "co" );
const fixturify = require( "fixturify" );

const expectedWatchOutput = require( "./fixtures/expected/watch-tap-outputs" );
const executeHelper = require( "./helpers/execute" );

// Executes the provided command from within the fixtures directory
function execute( command ) {
const cwd = process.cwd();
process.chdir( path.join( __dirname, "fixtures" ) );

const execution = exec( command, { stdio: [ null, null, null, "ipc" ] } );

process.chdir( cwd );

return execution;
return executeHelper( command, { stdio: [ null, null, null, "ipc" ] } );
}

const fixturePath = path.join( __dirname, "fixtures", "watching" );
Expand Down

0 comments on commit b385b83

Please sign in to comment.