Skip to content

Commit

Permalink
improved the default process exit handler
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Jul 18, 2014
1 parent fb0d894 commit f973f0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 10 additions & 5 deletions bin/_clirunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ CliRunner.prototype = {
if (!err.message) {
err.message = 'There was an error while running the test.';
}

if (this.test_settings.output) {
console.error(Logger.colors.red(err.message));
console.log(Logger.colors.red(err.message));
}

process.exit(1);
}
},
Expand Down Expand Up @@ -403,8 +401,10 @@ CliRunner.prototype = {
var self = this;

this.startSelenium(function() {
self.startChildProcesses(envs, function(o) {
self.startChildProcesses(envs, function(o, code) {
self.stopSelenium();
console.log('___ CODE___', code)
process.exit(code);
});
});

Expand Down Expand Up @@ -457,6 +457,7 @@ CliRunner.prototype = {

var prevIndex = 0;
var output = {};
var globalExitCode = 0;
var writeToSdtout = function(data, item, index) {
data = data.replace(/^\s+|\s+$/g, '');
output[item] = output[item] || [];
Expand Down Expand Up @@ -490,6 +491,7 @@ CliRunner.prototype = {
var cliArgs = self.getChildProcessArgs(mainModule);
cliArgs.push('-e', item, '__parallel-mode');
var env = process.env;

setTimeout(function() {
env.__NIGHTWATCH_PARALLEL_MODE = 1;
env.__NIGHTWATCH_ENV = item;
Expand All @@ -512,6 +514,9 @@ CliRunner.prototype = {
});

child.on('close', function (code) {
if (code) {
globalExitCode = 2;
}
if (!self.settings.live_output) {
var child_output = output[item];
for (var i = 0; i < child_output.length; i++) {
Expand All @@ -521,7 +526,7 @@ CliRunner.prototype = {
}

if (index === (envs.length - 1)) {
finishCallback(output);
finishCallback(output, globalExitCode);
}
});
}, index * 10);
Expand Down
8 changes: 4 additions & 4 deletions lib/runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ module.exports = new (function() {

function processListener(finishCallback) {
process.on('exit', function (code) {
if (globalResults.errors > 0 || globalResults.failed > 0) {
process.exit(1);
} else {
process.exit(code);
var exitCode = 0;
if (code === 0 && (globalResults.errors > 0 || globalResults.failed > 0)) {
exitCode = 1;
}
process.exit(exitCode);
});
process.on('uncaughtException', function (err) {
finishCallback({
Expand Down

0 comments on commit f973f0a

Please sign in to comment.