Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Commit

Permalink
Fix JS code lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlow Payne committed Jan 13, 2016
1 parent 8561932 commit 4d3984a
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 82 deletions.
12 changes: 6 additions & 6 deletions assertions/elementsPresent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ var async = require('async'),
util = require('util'),
events = require('events');

function Assertion() {
var Assertion = function() {
events.EventEmitter.call(this);
this.cb = null;
this.abortOnFailure = true;
this.selector = null;
}
};

util.inherits(Assertion, events.EventEmitter);

Expand Down Expand Up @@ -51,7 +51,7 @@ Assertion.prototype.checkElements = function() {
var found = [];
var selectors = this.selectors;

function checkElement(selector, cb) {
var checkElement = function(selector, cb) {
self.api.element.call(self, self.client.locateStrategy, selector, function(result) {
var value;

Expand All @@ -67,9 +67,9 @@ Assertion.prototype.checkElements = function() {

cb();
});
}
};

function returnResults(err) {
var returnResults = function(err) {
var result = missing.length;
var msg, passed;

Expand All @@ -87,7 +87,7 @@ Assertion.prototype.checkElements = function() {
self.client.assertion(passed, result, 0, msg, false);
self.cb(result);
self.emit('complete');
}
};

async.each(selectors, checkElement, returnResults);
};
Expand Down
12 changes: 6 additions & 6 deletions assertions/elementsVisible.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ var async = require('async'),
util = require('util'),
events = require('events');

function Assertion() {
var Assertion = function() {
events.EventEmitter.call(this);
this.cb = null;
this.abortOnFailure = true;
this.selector = null;
}
};

util.inherits(Assertion, events.EventEmitter);

Expand All @@ -50,7 +50,7 @@ Assertion.prototype.checkElements = function() {
var found = [];
var selectors = this.selectors;

function checkElement(selector, cb) {
var checkElement = function(selector, cb) {
self.api.isVisible.call(self, selector, function(result) {
var value;

Expand All @@ -66,9 +66,9 @@ Assertion.prototype.checkElements = function() {

cb();
});
}
};

function returnResults(err) {
var returnResults = function(err) {
var result = missing.length;
var msg, passed;

Expand All @@ -86,7 +86,7 @@ Assertion.prototype.checkElements = function() {
self.client.assertion(passed, result, 0, msg, false);
self.cb(result);
self.emit('complete');
}
};

async.each(selectors, checkElement, returnResults);
};
Expand Down
4 changes: 2 additions & 2 deletions assertions/templateName.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
var util = require('util'),
events = require('events');

function Assertion() {
var Assertion = function() {
events.EventEmitter.call(this);
this.cb = null;
this.abortOnFailure = true;
this.expected = null;
}
};

util.inherits(Assertion, events.EventEmitter);

Expand Down
30 changes: 15 additions & 15 deletions commands/htmlCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ var mkdirp = require('mkdirp');
var mkdirpSync = function(path) {
try {
mkdirp.sync(path);
} catch(e) {
if ( e.code != 'EEXIST' ) throw e;
} catch (e) {
if ( e.code !== 'EEXIST' ) throw e;
}
}
};

exports.command = function(fileName, callback) {
if (fileName && typeof fileName !== 'string') {
Expand All @@ -17,19 +17,19 @@ exports.command = function(fileName, callback) {

var htmlCheck = /^\w+\.html$/;

if (!htmlCheck.test(fileName)){
if (!htmlCheck.test(fileName)) {
throw new Error('htmlCapture expects first parameter to be camelCased alphanumeric string ending with ".html"');
}

var client = this;
var filePath = "tests/fixtures/";
var filePath = 'tests/fixtures/';
var fileLocation = filePath + fileName;
var messages = {
success: 'Wrote HTML fixture to ' + fileLocation + ' after ',
failure: 'Failed to write HTML fixture after '
};
success: 'Wrote HTML fixture to ' + fileLocation + ' after ',
failure: 'Failed to write HTML fixture after '
};

client.source(function (result){
client.source(function(result) {
// Source will be stored in result.value. IE:
// console.log(result.value);

Expand All @@ -38,11 +38,11 @@ exports.command = function(fileName, callback) {

// Now save result.value to "../../fixtures/contact.html" in order to update the fixture.
fs.writeFile(fileLocation, result.value, function(error) {
if (error) {
console.error("write error: " + error.message);
} else {
console.log("Successful Write to " + fileLocation);
}
if (error) {
console.error('Write error: ' + error.message);
} else {
console.log('Successful write to ' + fileLocation);
}
});
});
};
};
6 changes: 3 additions & 3 deletions commands/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* argument when you call preview(). Upon completion, waitUntilMobified
* is called, to be sure that the adaptation is complete.
*
* If `site.json` does not exist, this command will just go to the specified URL.
* If `site.json` does not exist, this command will just go to the specified URL.
*
* ```
* this.demoTest = function (client) {
Expand Down Expand Up @@ -40,7 +40,7 @@ var qs = require('querystring');
exports.command = function(url, callback) {
var browser = this;

if (siteConfig) {
if (siteConfig) {
var site = siteConfig.profiles[siteConfig.activeProfile];

if (typeof url === 'function') {
Expand Down Expand Up @@ -87,4 +87,4 @@ exports.command = function(url, callback) {
}
});
}
};
};
4 changes: 2 additions & 2 deletions commands/waitForAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ var events = require('events');
* @api commands
*/

function WaitForAnimation() {
var WaitForAnimation = function() {
events.EventEmitter.call(this);
}
};

util.inherits(WaitForAnimation, events.EventEmitter);

Expand Down
4 changes: 2 additions & 2 deletions commands/waitForCondition.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var util = require('util'),
events = require('events');

function CommandAction() {
var CommandAction = function() {
events.EventEmitter.call(this);
this.startTimer = null;
this.cb = null;
this.ms = null;
this.selector = null;
this.protocol = require('nightwatch/lib/api/protocol.js')(this.client);
}
};

util.inherits(CommandAction, events.EventEmitter);

Expand Down
6 changes: 3 additions & 3 deletions commands/waitForUrl.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
var util = require('util'),
events = require('events');

function WaitForUrl() {
var WaitForUrl = function() {
events.EventEmitter.call(this);
this.startTimer = null;
this.cb = null;
this.ms = null;
this.selector = null;
this.protocol = require('nightwatch/lib/api/protocol.js')(this.client);
}
};

util.inherits(WaitForUrl, events.EventEmitter);

Expand Down Expand Up @@ -57,7 +57,7 @@ WaitForUrl.prototype.check = function() {

this.protocol.url(function(result) {
var now = new Date().getTime();

if (result.status === 0 && result.value === self.url) {
setTimeout(function() {
var msg = self.messages.success + (now - self.startTimer) + ' milliseconds.';
Expand Down
36 changes: 19 additions & 17 deletions tests/nightwatch.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
var nightwatch = require('../node_modules/nightwatch');

module.exports = {
init : function(callback) {
return nightwatch.client({
// desiredCapabilities: {
// browserName: 'chrome'
// },
custom_commands_path: '../commands',
custom_assertions_path: '../assertions',
selenium_port : 10195,
silent : true,
output : false
}).start().once('error', function() {
if (callback) {
callback();
}
process.exit();
});
}
init : function(callback) {
return nightwatch.client({
// desiredCapabilities: {
// browserName: 'chrome'
// },
/* eslint-disable camelcase */
custom_commands_path: '../commands',
custom_assertions_path: '../assertions',
selenium_port : 10195,
/* eslint-enable camelcase */
silent : true,
output : false
}).start().once('error', function() {
if (callback) {
callback();
}
process.exit();
});
}
};
47 changes: 22 additions & 25 deletions tests/run_tests.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
try {
var args = process.argv, reporter_type = 'default';
var reporters = require('nodeunit').reporters;
var args = process.argv, reporterType = 'default';
var reporters = require('nodeunit').reporters;

if (args.length == 3) {
reporter_type = args[2];
if (args.length === 3) {
reporterType = args[2];

if (!(reporter_type in reporters)) {
console.error('Invalid reporter_type specified', reporter_type);
process.exit();
if (!(reporterType in reporters)) {
console.error('Invalid reporterType specified', reporterType);
process.exit();
}
}
}

var reporter = reporters[reporter_type];
var options = require('./nodeunit.json');
}
catch(e) {
console.log(e);
console.log('Cannot find nodeunit module.');
process.exit();
var reporter = reporters[reporterType];
var options = require('./nodeunit.json');
} catch (e) {
console.log(e);
console.log('Cannot find nodeunit module.');
process.exit();
}

process.chdir(__dirname);

try {
var server = require('mockserver').init();
server.on('listening', function() {
reporter.run(['src'], options, function() {
server.close();
var server = require('mockserver').init();
server.on('listening', function() {
reporter.run(['src'], options, function() {
server.close();
});
});
});


//reporter.run(['src/commands'], options);
//reporter.run(['src/commands'], options);
} catch (err) {
console.log(err);
process.exit();
console.log(err);
process.exit();
}
2 changes: 1 addition & 1 deletion tests/src/testElementsVisibleAssertion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

module.exports = {
setUp: function (callback) {
setUp: function(callback) {
callback();
},

Expand Down

0 comments on commit 4d3984a

Please sign in to comment.