Skip to content

Commit

Permalink
refactor: process.execPath -> common.nodeBinPath
Browse files Browse the repository at this point in the history
Move process.execPath with common.nodeBinPath until we have a fix for
compatibility with electron.
  • Loading branch information
nfischer committed Dec 28, 2016
1 parent 92a7963 commit eb13b72
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function cmdSync(cmd, args, opts, pipe) {

var proc;
try {
proc = child.spawnSync(process.execPath, [
proc = child.spawnSync(common.nodeBinPath, [
path.join(__dirname, 'child.js'),
stdoutFile,
stderrFile,
Expand Down
4 changes: 4 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ function log() {
}
exports.log = log;

// TODO(nate): make this compatible with electron
// The path to the NodeJS binary. This is mainly used for exec() and cmd()
exports.nodeBinPath = process.execPath;

// Shows error message. Throws if config.fatal is true
function error(msg, _code, options) {
// Validate input
Expand Down
15 changes: 8 additions & 7 deletions test/cmd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var shell = require('..');
var common = require('../src/common');

var assert = require('assert');
var path = require('path');
Expand Down Expand Up @@ -36,33 +37,33 @@ shell.config.fatal = oldFatal;
//

// check if stdout goes to output
result = shell.cmd(process.execPath, '-e', 'console.log(1234);');
result = shell.cmd(common.nodeBinPath, '-e', 'console.log(1234);');
assert.ok(!shell.error());
assert.equal(result.code, 0);
assert.equal(result.stdout, '1234\n');

// check if stderr goes to output
result = shell.cmd(process.execPath, '-e', 'console.error(1234);');
result = shell.cmd(common.nodeBinPath, '-e', 'console.error(1234);');
assert.ok(!shell.error());
assert.equal(result.code, 0);
assert.equal(result.stdout, '');
assert.equal(result.stderr, '1234\n');

// check if stdout + stderr go to output
result = shell.cmd(process.execPath, '-e', 'console.error(1234); console.log(666);');
result = shell.cmd(common.nodeBinPath, '-e', 'console.error(1234); console.log(666);');
assert.ok(!shell.error());
assert.equal(result.code, 0);
assert.equal(result.stdout, '666\n');
assert.equal(result.stderr, '1234\n');

// check exit code
result = shell.cmd(process.execPath, '-e', 'process.exit(12);');
result = shell.cmd(common.nodeBinPath, '-e', 'process.exit(12);');
assert.ok(shell.error());
assert.equal(result.code, 12);

// interaction with cd
shell.cd('resources/external');
result = shell.cmd(process.execPath, 'node_script.js');
result = shell.cmd(common.nodeBinPath, 'node_script.js');
assert.ok(!shell.error());
assert.equal(result.code, 0);
assert.equal(result.stdout, 'node_script_1234\n');
Expand Down Expand Up @@ -97,14 +98,14 @@ assert.strictEqual(result.toString(), result.stdout);

// TODO(nate): make it exactly equivalent to stderr, unless stderr === ''
// shell.error() contains the stderr of external command in the case of an error
result = shell.cmd(process.execPath, '-e', 'console.error(1234); process.exit(1);');
result = shell.cmd(common.nodeBinPath, '-e', 'console.error(1234); process.exit(1);');
assert.equal(shell.error(), 'cmd: ' + result.stderr);
assert.equal(result.code, 1);
assert.equal(result.stdout, '');
assert.equal(result.stderr, '1234\n');

// option: realtimeOutput === false
result = shell.cmd(process.execPath, '-e', 'console.error(1234); console.log(5678);', {
result = shell.cmd(common.nodeBinPath, '-e', 'console.error(1234); console.log(5678);', {
realtimeOutput: false
});
assert.ok(!shell.error());
Expand Down

0 comments on commit eb13b72

Please sign in to comment.