Skip to content

Commit

Permalink
fixed a problem in injectScript command, another one in the runner an…
Browse files Browse the repository at this point in the history
…d some slight refactoring
  • Loading branch information
beatfactor committed Jul 24, 2014
1 parent 18cb8f2 commit 0e62e16
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
9 changes: 7 additions & 2 deletions bin/_clirunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var fs = require('fs');
var path = require('path');

var SETTINGS_DEPRECTED_VAL = './settings.json';
var SETTINGS_JS_FILE = './nightwatch.conf.js';

function CliRunner(argv) {
this.settings = null;
Expand Down Expand Up @@ -33,8 +34,11 @@ CliRunner.prototype = {
// use default nightwatch.json file if we haven't received another value
if (this.cli.command('config').isDefault(this.argv.c)) {
var defaultValue = this.cli.command('config').defaults();
var localJsValue = path.resolve(SETTINGS_JS_FILE);

if (fs.existsSync(defaultValue)) {
if (fs.existsSync(SETTINGS_JS_FILE)) {
this.argv.c = localJsValue;
} else if (fs.existsSync(defaultValue)) {
this.argv.c = path.join(path.resolve('./'), this.argv.c);
} else if (fs.existsSync(SETTINGS_DEPRECTED_VAL)) {
this.argv.c = path.join(path.resolve('./'), SETTINGS_DEPRECTED_VAL);
Expand Down Expand Up @@ -142,8 +146,9 @@ CliRunner.prototype = {
err.message = 'There was an error while running the test.';
}
if (this.test_settings.output) {
console.log(Logger.colors.red(err.message));
process.stderr.write('\n' + Logger.colors.red(err.message));
}

process.exit(1);
}
},
Expand Down
8 changes: 4 additions & 4 deletions lib/core/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ module.exports = new (function() {
*/
function makeAssertion(prop, abortOnFailure) {
return function() {
var passed, expected = null;
var actual = arguments[0];

var passed;
var expected;
var actual;
var lastArgument = arguments[arguments.length-1];
var isLastArgString = typeof lastArgument === 'string';
var message = isLastArgString &&
(arguments.length > 2 || typeof arguments[0] === 'boolean') &&
lastArgument || (typeof arguments[0] === 'function' && '[Function]') ||
'' + actual;
('' + actual);

try {
assertModule[prop].apply(null, arguments);
Expand Down
30 changes: 14 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,32 +289,30 @@ Nightwatch.prototype.runProtocolAction = function(requestOptions, callback) {
request.emit('result', result, response);
})
.on('result', function(result) {
if (callback) {
if (typeof callback != 'function') {
var error = new Error('Callback parameter is not a function - ' + typeof(callback) + ' passed: "' + callback + '"');
self.errors.push(error.stack);
self.results.errors++;
} else {
try {
if (typeof callback != 'function') {
var error = new Error('Callback parameter is not a function - ' + typeof(callback) + ' passed: "' + callback + '"');
self.errors.push(error.stack);
self.results.errors++;
} else {
callback.call(self.api, result);
}
callback.call(self.api, result);
} catch (ex) {
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(' ' + Logger.colors.red(firstLine));
console.log(stack.join('\n'));

self.results.errors++;
}
}

if (result.lastScreenshotFile && self.results.tests.length > 0) {
var lastTest = self.results.tests[self.results.tests.length-1];
lastTest.screenshots = lastTest.screenshots || [];
lastTest.screenshots.push(result.lastScreenshotFile);
delete result.lastScreenshotFile;
}
if (result.lastScreenshotFile && self.results.tests.length > 0) {
var lastTest = self.results.tests[self.results.tests.length-1];
lastTest.screenshots = lastTest.screenshots || [];
lastTest.screenshots.push(result.lastScreenshotFile);
delete result.lastScreenshotFile;
}

});

return request;
Expand Down
7 changes: 3 additions & 4 deletions lib/runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ module.exports = new (function() {
}

if (client.terminated) {
process.exit(2);
// moduleCallback(null, keys);
moduleCallback(null, keys);
} else {
setTimeout(next, 0);
}
Expand Down Expand Up @@ -474,11 +473,11 @@ module.exports = new (function() {
console.log('\n' + Logger.colors.cyan(testSuiteName, Logger.colors.background.black));
console.log(Logger.colors.purple(new Array(testSuiteName.length + 1).join('=')));
}
runModule(module, opts, moduleName, moduleKey, function(err, modulekeys) {
runModule(module, opts, moduleName, moduleKey, function moduleCallback(err, modulekeys) {
if (fullpaths.length) {
setTimeout(function() {
runTestModule(err, fullpaths);
}, 0);
}, 1000);
} else {
if (opts.output) {
printTotalResults(globalResults, modulekeys, globalStartTime);
Expand Down
2 changes: 1 addition & 1 deletion lib/selenium/client-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ module.exports = function(client) {
args.push(id);
}

return this.execute(function(u,i) {/* jshint browser:true */return (function(d){var e=d.createElement('script');var m=d.getElementsByTagName('script')[0];e.src=u;if(i){e.id=i;}m.parentNode.insertBefore(e,m);return e;})(document);}, args, callback);
return this.execute(function(u,i) {/* jshint browser:true */return (function(d){var e=d.createElement('script');var m=d.getElementsByTagName('head')[0];e.src=u;if(i){e.id=i;}m.appendChild(e);return e;})(document);}, args, callback);
}
};
};

0 comments on commit 0e62e16

Please sign in to comment.