Skip to content

Commit

Permalink
added a second argument to finishCallback in runner to hold the globa…
Browse files Browse the repository at this point in the history
…l success/failure status
  • Loading branch information
beatfactor committed Mar 21, 2014
1 parent 74902df commit e4fb7e3
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = new (function() {
client = Nightwatch.client(opts);
} catch (err) {
console.log(err.stack);
finishCallback(err);
finishCallback(err, false);
return;
}
var keys = Object.keys(module);
Expand Down Expand Up @@ -155,16 +155,6 @@ module.exports = new (function() {
}
}

function processExitListener() {
process.on('exit', function(code) {
if (globalResults.errors > 0 || globalResults.failed > 0) {
process.exit(1);
} else {
process.exit(code);
}
});
}

function wrapTest(setUp, tearDown, fn, context, onComplete, client) {
return function (c) {
context.client = c;
Expand Down Expand Up @@ -289,6 +279,7 @@ module.exports = new (function() {
var modules = {};
var curModule;
var paths;

finishCallback = finishCallback || function() {};

if (typeof files == 'string') {
Expand All @@ -309,13 +300,13 @@ module.exports = new (function() {
console.log('using source folder', paths);
return;
}

var module;
var modulePath = fullpaths.shift();
try {
module = require(modulePath);
} catch (err) {
finishCallback(err);
finishCallback(err, false);
throw err;
}

Expand Down Expand Up @@ -344,14 +335,15 @@ module.exports = new (function() {

var diffInFolder = getPathDiff(modulePath, aditional_opts);
var output = path.join(aditional_opts.output_folder, diffInFolder);
var success = globalResults.failed === 0 && globalResults.errors === 0;
if (output === false) {
finishCallback(null);
finishCallback(null, success);
} else {
mkpath(output, function(err) {
if (err) {
console.log(Logger.colors.yellow('Output folder doesn\'t exist and cannot be created.'));
console.log(err.stack);
finishCallback(null);
finishCallback(null, success);
return;
}

Expand All @@ -360,15 +352,13 @@ module.exports = new (function() {
console.log(Logger.colors.yellow('Warning: Failed to save report file to folder: ' + output));
console.log(err.stack);
}
finishCallback(null);
finishCallback(null, success);
});
});
}
}
}, finishCallback);
}, opts);

processExitListener();
};
})();

0 comments on commit e4fb7e3

Please sign in to comment.