Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: Verify the shell option works properly on execFile
Useful for executing in a shell because it accepts arguments as
an array instead of a string as exec does.
Depending on the circumstances,
that can prove to be useful if the arguments are already prepared.
  • Loading branch information
jvelezpo committed Jan 25, 2018
commit ce61105cb6dabf09c8e579dba23942229159c997
8 changes: 8 additions & 0 deletions test/parallel/test-child-process-execfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { getSystemErrorName } = require('util');
const fixtures = require('../common/fixtures');

const fixture = fixtures.path('exit.js');
const execOpts = { encoding: 'utf8', shell: process.env.SHELL };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.env.SHELL is likely to not be set on Windows so this will end up being undefined.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct mr @richardlau, i tested it on another pc running windows and process.env.SHELL was undefined.
Thanks for feedback I appreciate it.


{
execFile(
Expand Down Expand Up @@ -39,3 +40,10 @@ const fixture = fixtures.path('exit.js');
child.kill();
child.emit('close', code, null);
}

{
// Verify the shell option works properly
execFile('ls', [process.execPath, '*'], execOpts, common.mustCall((err) => {
assert.strictEqual(err, null);
Copy link
Copy Markdown
Member

@BridgeAR BridgeAR Jan 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a perfect place for assert.ifError.

}));
}
6 changes: 6 additions & 0 deletions test/sequential/test-child-process-execsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const TIMER = 200;
const SLEEP = 2000;

const start = Date.now();
const execOpts = { encoding: 'utf8', shell: process.env.SHELL };
let err;
let caught = false;

Expand Down Expand Up @@ -141,3 +142,8 @@ assert.strictEqual(ret, `${msg}\n`);
return true;
});
}

// Verify the shell option works properly
assert.doesNotThrow(() => {
execFileSync('ls', [process.execPath, '*'], execOpts);
});