Skip to content

Commit

Permalink
improved error handling and reporting and attempting to fix #47.
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Feb 21, 2014
1 parent 72f6266 commit 0a74f74
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
16 changes: 11 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,19 @@ Nightwatch.prototype.runProtocolCommand = function(requestOptions, callback) {
try {
if (typeof callback != 'function') {
var error = new Error('Callback parameter is not a function - ' + typeof(callback) + ' passed: "' + callback + '"');
this.errors.push(error.stack)
this.results.errors++;
throw error;
self.errors.push(error.stack);
self.results.errors++;
} else {
callback.call(self, result);
}
callback.call(self, result);
} catch (ex) {
console.log(ex.stack)
self.errors.push('Error while running tests: ' + ex.message);
var stack = ex.stack.split('\n');
var firstLine = stack.shift();
console.log(' ' + Logger.colors.light_green(firstLine));
console.log(stack.join('\n'));

self.results.errors++;
}
}
});
Expand Down
23 changes: 15 additions & 8 deletions runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module.exports = new (function() {
testresults.skipped += results.skipped;
testresults.tests += results.tests.length;
if (this.client.terminated) {
callback(testresults);
callback(null, testresults);
} else {
setTimeout(next, 0);
}
Expand All @@ -107,14 +107,15 @@ module.exports = new (function() {
testresults.errors++;
client.terminate();
error = true;
callback(err, testresults);
}

if (!error) {
client.start();
}

} else {
callback(testresults);
callback(null, testresults);
}
}

Expand Down Expand Up @@ -176,10 +177,10 @@ module.exports = new (function() {
return cb(err);
}
list.sort();

var modules = list.filter(function (filePath) {
var filename = filePath.split('/').slice(-1)[0];
return opts.filter ?
return opts.filter ?
minimatch(filename, opts.filter) :
extensionPattern.exec(filePath);
});
Expand Down Expand Up @@ -261,12 +262,18 @@ module.exports = new (function() {
}

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

var moduleName = modulePath.split(path.sep).pop();
globalresults.modules[moduleName] = [];
console.log('\n' + Logger.colors.cyan('[ ' + moduleName + ' module ]'));

runModule(module, opts, moduleName, function(testresults) {
runModule(module, opts, moduleName, function(err, testresults) {
globalresults.passed += testresults.passed;
globalresults.failed += testresults.failed;
globalresults.errors += testresults.errors;
Expand All @@ -284,11 +291,11 @@ module.exports = new (function() {

var output = aditional_opts.output_folder;
if (output === false) {
finishCallback();
finishCallback(null);
} else {
ensureDir(output, function() {
Reporter.save(globalresults, output);
finishCallback();
finishCallback(null);
});
}
}
Expand Down

0 comments on commit 0a74f74

Please sign in to comment.