Skip to content

Commit b385b83

Browse files
Krinkletrentmwillis
authored andcommitted
Tests: Unbreak test:cli due to unknown 'qunit' command
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.
1 parent 62374ea commit b385b83

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

test/cli/helpers/execute.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ const path = require( "path" );
44
const exec = require( "execa" ).shell;
55

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

11-
const execution = exec( command );
13+
command = command.replace( /^qunit\b/, "../../../bin/qunit" );
14+
const execution = exec( command, execaOptions );
1215

1316
process.chdir( cwd );
1417

test/cli/watch.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@
22

33
const fs = require( "fs-extra" );
44
const path = require( "path" );
5-
const exec = require( "execa" ).shell;
65
const co = require( "co" );
76
const fixturify = require( "fixturify" );
87

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

1111
// Executes the provided command from within the fixtures directory
1212
function execute( command ) {
13-
const cwd = process.cwd();
14-
process.chdir( path.join( __dirname, "fixtures" ) );
15-
16-
const execution = exec( command, { stdio: [ null, null, null, "ipc" ] } );
17-
18-
process.chdir( cwd );
19-
20-
return execution;
13+
return executeHelper( command, { stdio: [ null, null, null, "ipc" ] } );
2114
}
2215

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

0 commit comments

Comments
 (0)