Skip to content

fix: Exit code is 0 when first command succeeds and second #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function close (code) {
var i, len, closed = 0, opened = 0;

for (i = 0, len = children.length; i < len; i++) {
if (!children[i].exitCode) {
if (!children[i].exitCode && children[i].exitCode !== 0) {
opened++;
children[i].removeAllListeners('close');
children[i].kill("SIGINT");
Expand Down
15 changes: 15 additions & 0 deletions test/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ else
# children
waitingProcess = "\"node -e 'setTimeout(function(){},10000);'\""
failingProcess = "\"node -e 'throw new Error();'\""
shortProcess = "\"echo 1\""

usageInfo = """
-h, --help output usage information
Expand Down Expand Up @@ -96,6 +97,20 @@ describe "parallelshell", ->
ps.exitCode.should.equal 1
done()

it "should close sibling processes on child error and exit with error (#1)", (done) ->
ps = spawnParallelshell([shortProcess,failingProcess].join(" "))
spyOnPs ps,2
ps.on "close", () ->
ps.exitCode.should.equal 1
done()

it "should close sibling processes on child error and exit with error (#2)", (done) ->
ps = spawnParallelshell([failingProcess,waitingProcess].join(" "))
spyOnPs ps,2
ps.on "close", () ->
ps.exitCode.should.equal 1
done()

it "should wait for sibling processes on child error when called with -w or --wait", (done) ->
ps = spawnParallelshell(["-w",waitingProcess,failingProcess,waitingProcess].join(" "))
ps2 = spawnParallelshell(["--wait",waitingProcess,failingProcess,waitingProcess].join(" "))
Expand Down