From 6d26a353a0a6554ccd1f08b73275e0bdb3ff971d Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Tue, 13 Oct 2015 15:19:53 +0100 Subject: [PATCH] Return exit code 0 on delayed child process error Now only kills running processes. with @fabiosantoscode --- index.js | 2 +- test/index.coffee | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 441a6a7..f3fd1aa 100755 --- a/index.js +++ b/index.js @@ -76,7 +76,7 @@ function close (code) { var i, len, closeHandler, closed = 0, opened = 0; for (i = 0, len = children.length; i < len; i++) { - if (!children[i].exitCode) { + if (children[i].exitCode === null) { opened++; children[i].removeAllListeners('close'); if (process.platform != "win32") { diff --git a/test/index.coffee b/test/index.coffee index aa114c4..0b433a9 100644 --- a/test/index.coffee +++ b/test/index.coffee @@ -16,6 +16,8 @@ else # children waitingProcess = (time=10000) -> return "\"node -e 'setTimeout(function(){},#{time});'\"" +waitingFailingProcess = (time=10000) -> + return "\"node -e 'setTimeout(function(){ throw new Error(); },#{time});'\"" failingProcess = "\"node -e 'throw new Error();'\"" usageInfo = """ @@ -86,6 +88,13 @@ describe "parallelshell", -> ps.exitCode.should.equal 1 done() + it "should close with exitCode 1 on delayed child error", (done) -> + ps = spawnParallelshell([waitingFailingProcess(100),waitingProcess(1),waitingProcess(500)].join(" ")) + spyOnPs ps, 2 + ps.on "exit", () -> + ps.exitCode.should.equal 1 + done() + it "should run with a normal child", (done) -> ps = spawnParallelshell(waitingProcess()) spyOnPs ps, 1 @@ -96,7 +105,6 @@ describe "parallelshell", -> killPs(ps) ),150 - it "should close sibling processes on child error", (done) -> ps = spawnParallelshell([waitingProcess(),failingProcess].join(" ")) spyOnPs ps,2