Skip to content

Commit

Permalink
Add eslint configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Oct 13, 2015
1 parent fb042f5 commit 33f0c35
Show file tree
Hide file tree
Showing 34 changed files with 212 additions and 201 deletions.
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "airbnb/legacy",
"rules": {
"id-length": 0,
"vars-on-top": 0,
"strict": [2, "global"],
"no-param-reassign": 0
}
}
4 changes: 2 additions & 2 deletions lib/assert/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports.elementHasAttributes = function elementHasAttributes(doc, selector, attr
selector = doc;
doc = [
'elementHasAttributes - selector:' + selector,
'attributesObject:' + JSON.stringify(attributesObject)
'attributesObject:' + JSON.stringify(attributesObject),
].join('\n');
} else {
assert.hasType('elementHasAttributes(docstring, selector, attributesObject) - requires String docstring', String, doc);
Expand All @@ -47,7 +47,7 @@ exports.elementHasAttributes = function elementHasAttributes(doc, selector, attr

var element = this._getElement(selector);

_.each(attributesObject, function(val, attribute) {
_.each(attributesObject, function verifyAttribute(val, attribute) {
var actualVal = element.get(attribute);
var attrDoc = util.format(
'%s\nattribute %j was expected to be %j but was %j.',
Expand Down
7 changes: 3 additions & 4 deletions lib/assert/imgLoaded_client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* jshint browser: true */
'use strict';

// returns true if the image is loaded and decoded,
Expand All @@ -21,15 +22,13 @@ module.exports = function imgLoaded(selector) {
if (imgs.length !== 1) {
return imgs.length;
}
img = imgs[0];
var img = imgs[0];

if (!img.src) {
var oops = describe(img);
if ((img.tagName || '').match(/^img$/i)) {
return 'src-less ' + describe(img);
} else {
return 'non-image ' + describe(img);
}
return 'non-image ' + describe(img);
}

return img.complete && img.naturalWidth ? true : img.src;
Expand Down
4 changes: 2 additions & 2 deletions lib/assert/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ function Assertions(driver, browser) {
_.each([
require('./element'),
require('./imgLoaded'),
require('./navigation')
], function(mixin) {
require('./navigation'),
], function applyMixin(mixin) {
_.extend(Assertions.prototype, mixin);
});

Expand Down
2 changes: 1 addition & 1 deletion lib/browser/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ exports._forwarded = [
'acceptAlert',
'dismissAlert',
'getAlertText',
'typeAlert'
'typeAlert',
];
8 changes: 4 additions & 4 deletions lib/browser/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ var getTestiumCookie = require('testium-cookie').getTestiumCookie;
exports._forwarded = [
// TODO: Port validateCookie to webdriver-http-sync
'setCookie',
'clearCookies'
'clearCookies',
];

exports.setCookies = function(cookies) {
exports.setCookies = function setCookies(cookies) {
_.each(cookies, this.setCookie, this);
return this;
}
};

exports.getCookie = function getCookie(name) {
assert.hasType('getCookie(name) - requires (String) name', String, name);
Expand All @@ -31,7 +31,7 @@ exports.clearCookie = function clearCookie(name) {
return this.setCookie({
name: name,
value: 'dummy', // setCookie doesn't allow null values
expiry: 0
expiry: 0,
});
};

Expand Down
4 changes: 2 additions & 2 deletions lib/browser/debug/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var logMap = {
'SEVERE': 'error',
'WARNING': 'warn',
'INFO': 'log',
'DEBUG': 'debug'
'DEBUG': 'debug',
};

function convertLogType(log) {
Expand All @@ -25,7 +25,7 @@ exports.filterLogs = function filterLogs(logs, type) {
if (!type) {
return { matched: logs };
}
return _.groupBy(logs, function(log) {
return _.groupBy(logs, function byMatched(log) {
return log.type === type ? 'matched' : 'rest';
});
};
4 changes: 2 additions & 2 deletions lib/browser/debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var TYPES = [
'error',
'warn',
'log',
'debug'
'debug',
];

var cachedLogs = [];
Expand All @@ -24,6 +24,6 @@ exports.getConsoleLogs = function getConsoleLogs(type) {
var logs = cachedLogs.concat(newLogs);

var filtered = filterLogs(logs, type);
cachedLogs = filtered.rest || []
cachedLogs = filtered.rest || [];
return filtered.matched || [];
};
18 changes: 8 additions & 10 deletions lib/browser/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var STALE_MESSAGE = /stale element reference/;
var NOT_FOUND_MESSAGE = new RegExp([
'Unable to locate element', // firefox message
'Unable to find element', // phantomjs message
'no such element', // chrome message
'no such element', // chrome message
].join('|'));

function visiblePredicate(shouldBeVisible, element) {
Expand Down Expand Up @@ -40,7 +40,7 @@ var isntVisibleFailure = _.partial(visibleFailure, false);

exports._forwarded = [
// TODO: port type assertion for selector to webdriver-http-sync
'getElements'
'getElements',
];

exports.getElementWithoutError = function getElementWithoutError(selector) {
Expand Down Expand Up @@ -73,24 +73,26 @@ exports.waitForElementVisible = function waitForElementVisible(selector, timeout

exports.waitForElementNotVisible = function waitForElementNotVisible(selector, timeout) {
return this._waitForElement(selector, isntVisiblePredicate, isntVisibleFailure, timeout);
}
};

exports.waitForElementExist = function waitForElementExist(selector, timeout) {
return this._waitForElement(selector, elementExistsPredicate, elementExistsFailure, timeout);
}
};

exports.click = function click(selector) {
return this.getExistingElement(selector).click();
};

function tryFindElement(self, selector, predicate, untilTime) {
var element, predicateResult;
var element;

while (Date.now() < untilTime) {
element = self.getElementWithoutError(selector);

try {
predicateResult = predicate(element);
if (predicate(element)) {
return element;
}
} catch (exception) {
// Occasionally webdriver throws an error about the element reference being
// stale. Let's handle that case as the element doesn't yet exist. All
Expand All @@ -99,10 +101,6 @@ function tryFindElement(self, selector, predicate, untilTime) {
throw exception;
}
}

if (predicateResult) {
return element;
}
}
return null;
}
Expand Down
23 changes: 11 additions & 12 deletions lib/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var builtIns = [
require('./input'),
require('./navigation'),
require('./page'),
require('./window')
require('./window'),
];

function Browser(driver, options) {
Expand All @@ -32,21 +32,20 @@ Browser.prototype.evaluate = function evaluate() {
assert.truthy(invocation, clientFunction);

switch (typeof clientFunction) {
case 'function':
clientFunction =
'return (' + clientFunction + ').apply(this, ' + JSON.stringify(args) + ');';
// fall-through

case 'string':
return this.driver.evaluate(clientFunction);

default:
throw new Error(invocation);
case 'function':
clientFunction =
'return (' + clientFunction + ').apply(this, ' + JSON.stringify(args) + ');';
/* falls through */
case 'string':
return this.driver.evaluate(clientFunction);

default:
throw new Error(invocation);
}
};

function forwardToDriver(method) {
Browser.prototype[method] = function() {
Browser.prototype[method] = function _forwarded() {
return this.driver[method].apply(this.driver, arguments);
};
}
Expand Down
13 changes: 6 additions & 7 deletions lib/browser/makeUrlRegExp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ function quoteRegExp(string) {
}

function bothCases(alpha) {
var dn, up;
up = alpha.toUpperCase();
dn = alpha.toLowerCase();
return "[" + up + dn + "]";
var up = alpha.toUpperCase();
var dn = alpha.toLowerCase();
return '[' + up + dn + ']';
}

var isHexaAlphaRE = /[a-f]/gi;
Expand All @@ -24,7 +23,7 @@ function matchCharacter(uriEncoded, hex) {
if (character === ' ') {
character += '|\\+';
}
return "(?:" + uriEncoded.replace(isHexaAlphaRE, bothCases) + "|" + character + ")";
return '(?:' + uriEncoded.replace(isHexaAlphaRE, bothCases) + '|' + character + ')';
}

var encodedCharRE = /%([0-9a-f]{2})/gi;
Expand All @@ -39,10 +38,10 @@ function matchURI(stringOrRegExp) {

function makeUrlRegExp(url, query) {
var expr = matchURI(url);
_.each(query || {}, function(val, key) {
_.each(query || {}, function queryParamMatcher(val, key) {
key = matchURI(key);
val = matchURI(val);
expr += "(?=(?:\\?|.*&)" + key + "=" + val + ")";
expr += '(?=(?:\\?|.*&)' + key + '=' + val + ')';
});
return new RegExp(expr);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var waitFor = require('./wait');

exports._forwarded = [
'refresh',
'getUrl'
'getUrl',
];

exports.navigateTo = function navigateTo(url, options) {
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ exports._forwarded = [
'getPageSource',
'getScreenshot',
'setPageSize',
'getPageSize'
'getPageSize',
];
13 changes: 5 additions & 8 deletions lib/browser/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,23 @@ var util = require('util');

var _ = require('lodash');

function testEqual(a, b) { return a === b; }

function matches(stringOrRegex, testUrl) {
return stringOrRegex.test(testUrl);
}

function createTest(stringOrRegex) {
function createTest(stringOrRegex, waitingFor) {
if (_.isString(stringOrRegex)) {
return _.partial(_.isEqual, stringOrRegex);
} else if (_.isRegExp(stringOrRegex)) {
return _.partial(matches, stringOrRegex);
} else {
throw new Error(
util.format('waitFor%s(urlStringOrRegex) - requires a string or regex param',
waitingFor));
}
throw new Error(
util.format('waitFor%s(urlStringOrRegex) - requires a string or regex param',
waitingFor));
}

function waitFor(stringOrRegex, waitingFor, getValue, timeout) {
var test = createTest(stringOrRegex);
var test = createTest(stringOrRegex, waitingFor);

var start = Date.now();
var currentValue;
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var assert = require('assertive');

exports._forwarded = [
'switchToWindow',
'closeWindow'
'closeWindow',
];

exports.switchToDefaultFrame = function switchToDefaultFrame() {
Expand Down
2 changes: 1 addition & 1 deletion lib/testium-driver-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function createDriver(testium) {

var browser = testium.browser = new Browser(driver, {
appUrl: 'http://127.0.0.1:' + config.get('app.port'),
getNewPageUrl: testium.getNewPageUrl
getNewPageUrl: testium.getNewPageUrl,
});
browser.assert = new Assertions(driver, browser);

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Sync interface for testium",
"main": "lib/testium-driver-sync.js",
"scripts": {
"test": "mocha"
"test": "eslint lib test && mocha"
},
"repository": {
"type": "git",
Expand All @@ -24,6 +24,9 @@
"homepage": "https://github.com/testiumjs/testium-driver-sync#readme",
"devDependencies": {
"babel-core": "^5.8.25",
"babel-eslint": "^4.1.3",
"eslint": "^1.6.0",
"eslint-config-airbnb": "~0.1.0",
"mocha": "^2.3.3",
"node-static": "~0.7.7",
"testium-core": "^1.1.2"
Expand Down
9 changes: 9 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "airbnb/base",
"env": {
"mocha": true
},
"rules": {
"id-length": 0
}
}
Loading

0 comments on commit 33f0c35

Please sign in to comment.