From ff38d2471f36815f3d56774092a8d298719fd4fb Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 24 Oct 2020 04:22:13 +0100 Subject: [PATCH] improve resilience against `npm` failures (#4239) --- test/jetstream.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/jetstream.js b/test/jetstream.js index 23c49b05..1eebdc6b 100644 --- a/test/jetstream.js +++ b/test/jetstream.js @@ -60,7 +60,7 @@ if (typeof phantom == "undefined") { var port = server.address().port; if (debug) { console.log("http://localhost:" + port + "/"); - } else { + } else (function install() { child_process.spawn(process.platform == "win32" ? "npm.cmd" : "npm", [ "install", "phantomjs-prebuilt@2.1.14", @@ -71,7 +71,10 @@ if (typeof phantom == "undefined") { ], { stdio: [ "ignore", 1, 2 ] }).on("exit", function(code) { - if (code) throw new Error("npm install failed!"); + if (code) { + console.log("npm install failed with code", code); + return install(); + } var program = require("phantomjs-prebuilt").exec(process.argv[1], port); program.stdout.pipe(process.stdout); program.stderr.pipe(process.stderr); @@ -82,7 +85,7 @@ if (typeof phantom == "undefined") { process.exit(0); }); }); - } + })(); }); server.timeout = 0; } else { -- 2.34.1