Skip to content

Commit

Permalink
test: fix test-child-process-flush-stdio on win
Browse files Browse the repository at this point in the history
This test cases tries to use the V6 "shell:true" option
on child_process.spawn that isn't in V4, therefore the
test failes when there is no "echo.exe" on Windows systems.
This fix implements the same functionality (cmd/c echo)
that the shell:true option would have given.
  • Loading branch information
Stewart X Addison committed Jan 31, 2017
1 parent f5c57c7 commit c55ad84
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions test/parallel/test-child-process-flush-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ const common = require('../common');
const assert = require('assert');

// Windows' `echo` command is a built-in shell command and not an external
// executable like on *nix
const opts = { shell: common.isWindows };

const p = cp.spawn('echo', [], opts);
// executable like on *nix. The V4 API does not have the "shell" option to
// spawn that we use in V4 and later so we can't use that here.
var p;
if (common.isWindows) {
p = cp.spawn('cmd.exe', ['/c', 'echo'], {});
} else {
p = cp.spawn('echo', [], {});
}

p.on('close', common.mustCall(function(code, signal) {
assert.strictEqual(code, 0);
Expand All @@ -19,7 +23,12 @@ p.stdout.read();

function spawnWithReadable() {
const buffer = [];
const p = cp.spawn('echo', ['123'], opts);
var p;
if (common.isWindows) {
p = cp.spawn('cmd.exe', ['/c', 'echo', '123'], {});
} else {
p = cp.spawn('echo', ['123'], {});
}
p.on('close', common.mustCall(function(code, signal) {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
Expand Down

0 comments on commit c55ad84

Please sign in to comment.