From 5af8ba8bf8d9a452c857cdb94096b8e2f1ae9b74 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 9 Jun 2016 22:07:07 -0700 Subject: [PATCH] Fixes an issue with runtests-parallel when global mocha is not installed. --- Jakefile.js | 9 +++++++++ scripts/mocha-parallel.js | 23 ++++++++--------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index cfcd4246046..4f0e231661e 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -740,16 +740,25 @@ function runConsoleTests(defaultReporter, runInParallel) { tests = tests ? ' -g "' + tests + '"' : ''; var cmd = "mocha" + (debug ? " --debug-brk" : "") + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run; console.log(cmd); + + var savedNodeEnv = process.env.NODE_ENV; + process.env.NODE_ENV = "development"; exec(cmd, function () { + process.env.NODE_ENV = savedNodeEnv; runLinter(); finish(); }, function(e, status) { + process.env.NODE_ENV = savedNodeEnv; finish(status); }); } else { + var savedNodeEnv = process.env.NODE_ENV; + process.env.NODE_ENV = "development"; runTestsInParallel(taskConfigsFolder, run, { testTimeout: testTimeout, noColors: colors === " --no-colors " }, function (err) { + process.env.NODE_ENV = savedNodeEnv; + // last worker clean everything and runs linter in case if there were no errors deleteTemporaryProjectOutput(); jake.rmRf(taskConfigsFolder); diff --git a/scripts/mocha-parallel.js b/scripts/mocha-parallel.js index 159dd630cc2..cc695729cbd 100644 --- a/scripts/mocha-parallel.js +++ b/scripts/mocha-parallel.js @@ -34,13 +34,7 @@ function discoverTests(run, options, cb) { console.log("Discovering tests..."); var cmd = "mocha -R " + require.resolve("./mocha-none-reporter.js") + " " + run; - var p = child_process.spawn( - process.platform === "win32" ? "cmd" : "/bin/sh", - process.platform === "win32" ? ["/c", cmd] : ["-c", cmd], { - windowsVerbatimArguments: true, - env: { NODE_ENV: "development" } - }); - + var p = spawnProcess(cmd); p.on("exit", function (status) { if (status) { cb(new Error("Process exited with code " + status)); @@ -87,18 +81,11 @@ function runTests(taskConfigsFolder, run, options, cb) { // Start the background process. var cmd = "mocha -t " + (options.testTimeout || 20000) + " -R tap --no-colors " + run + " --config='" + partition.file + "'"; - var p = child_process.spawn( - process.platform === "win32" ? "cmd" : "/bin/sh", - process.platform === "win32" ? ["/c", cmd] : ["-c", cmd], { - windowsVerbatimArguments: true, - env: { NODE_ENV: "development" } - }); - + var p = spawnProcess(cmd); var rl = readline.createInterface({ input: p.stdout, terminal: false }); - rl.on("line", onmessage); p.on("exit", onexit) @@ -259,6 +246,12 @@ function runTests(taskConfigsFolder, run, options, cb) { } } +function spawnProcess(cmd, options) { + var shell = process.platform === "win32" ? "cmd" : "/bin/sh"; + var prefix = process.platform === "win32" ? "/c" : "-c"; + return child_process.spawn(shell, [prefix, cmd], { windowsVerbatimArguments: true }); +} + function ProgressBars(options) { if (!options) options = {}; var open = options.open || '[';