Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
ESLINT all the sources
Browse files Browse the repository at this point in the history
  • Loading branch information
assaf committed Mar 25, 2015
1 parent aea34fd commit 41807a3
Show file tree
Hide file tree
Showing 42 changed files with 1,021 additions and 976 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.json
lib/**/*.js
20 changes: 20 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
parser: 'babel-eslint',
env: {
node: true,
es6: true
},
// http://eslint.org/docs/rules/
rules: {
strict: 0,
curly: [2, 'multi'],
quotes: [2, 'single'],
eol-last: [0],
no-mixed-requires: [0],
no-underscore-dangle: [0],
no-multi-spaces: 0,
no-var: 1,
key-spacing: 0,
no-script-url: 0
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@
},
"devDependencies": {
"babel": "4.7.12",
"babel-eslint": "^2.0.2",
"body-parser": "^1.12.0",
"cookie-parser": "^1.3.4",
"del": "^1.1.1",
"eslint": "^0.17.1",
"express": "^4.12.2",
"gulp": "^3.8.10",
"gulp-babel": "^4.0.0",
Expand Down
57 changes: 27 additions & 30 deletions src/assert.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Browser assertions convenience.

const assert = require("assert");
const { isRegExp } = require("util");
const URL = require("url");
const assert = require('assert');
const { isRegExp } = require('util');
const URL = require('url');


// Used to assert that actual matches expected value, where expected may be a function or a string.
function assertMatch(actual, expected, message) {
if (isRegExp(expected)) {
if (isRegExp(expected))
assert(expected.test(actual), message || `Expected '${actual}' to match ${expected}`);
} else if (typeof(expected) === "function") {
else if (typeof expected === 'function')
assert(expected(actual), message);
} else
else
assert.deepEqual(actual, expected, message);
}

Expand Down Expand Up @@ -57,18 +57,18 @@ module.exports = class Assert {
// object properties are tested against the actual URL (e.g. pathname, host,
// query).
url(expected, message) {
if (typeof(expected) === "string") {
if (typeof expected === 'string') {
const absolute = URL.resolve(this.browser.location.href, expected);
assertMatch(this.browser.location.href, absolute, message);
} else if (isRegExp(expected) || typeof(expected) === "function") {
} else if (isRegExp(expected) || typeof expected === 'function')
assertMatch(this.browser.location.href, expected, message);
} else {
else {
const url = URL.parse(this.browser.location.href, true);
for (let key in expected) {
let value = expected[key];
// Gracefully handle default values, e.g. document.location.hash for
// "/foo" is "" not null, not undefined.
let defaultValue = (key === "port") ? 80 : null;
let defaultValue = (key === 'port') ? 80 : null;
assertMatch(url[key] || defaultValue, value || defaultValue, message);
}
}
Expand All @@ -90,7 +90,7 @@ module.exports = class Assert {
// Assert that element matching selector exists.
element(selector, message) {
this.elements(selector, { exactly: 1 }, message);
}
}

// Assert how many elements matching selector exist.
//
Expand All @@ -102,11 +102,11 @@ module.exports = class Assert {
// If count is unspecified, defaults to at least one.
elements(selector, count, message) {
const elements = this.browser.queryAll(selector);
if (arguments.length == 1) {
if (arguments.length === 1)
this.elements(selector, { atLeast: 1});
} else if (Number.isInteger(count)) {
else if (Number.isInteger(count))
this.elements(selector, { exactly: count }, message);
} else {
else {
if (count.exactly)
assert.equal(elements.length, count.exactly,
message || `Expected ${count.exactly} elements matching '${selector}', found ${elements.length}`);
Expand All @@ -126,7 +126,7 @@ module.exports = class Assert {
for (let element of elements) {
let classNames = element.className.split(/\s+/);
assert(~classNames.indexOf(expected),
message || `Expected element '${selector}' to have class ${expected}, found ${classNames.join(", ")}`);
message || `Expected element '${selector}' to have class ${expected}, found ${classNames.join(', ')}`);
}
}

Expand All @@ -137,17 +137,17 @@ module.exports = class Assert {
for (let element of elements) {
let classNames = element.className.split(/\s+/);
assert(classNames.indexOf(expected) === -1,
message || `Expected element '${selector}' to not have class ${expected}, found ${classNames.join(", ")}`);
message || `Expected element '${selector}' to not have class ${expected}, found ${classNames.join(', ')}`);
}
}

// Asserts the selected element(s) has the expected class names.
className(selector, expected, message) {
const elements = this.browser.queryAll(selector);
assert(elements.length, `Expected selector '${selector}' to return one or more elements`);
const array = expected.split(/\s+/).sort().join(" ");
const array = expected.split(/\s+/).sort().join(' ');
for (let element of elements) {
let actual = element.className.split(/\s+/).sort().join(" ");
let actual = element.className.split(/\s+/).sort().join(' ');
assertMatch(actual, array,
message || `Expected element '${selector}' to have class ${expected}, found ${actual}`);
}
Expand Down Expand Up @@ -197,10 +197,10 @@ module.exports = class Assert {
assert(elements.length, `Expected selector '${selector}' to return one or more elements`);
const actual = elements
.map(elem => elem.textContent)
.join("")
.join('')
.trim()
.replace(/\s+/g, " ");
assertMatch(actual, expected || "", message);
.replace(/\s+/g, ' ');
assertMatch(actual, expected || '', message);
}


Expand All @@ -214,10 +214,9 @@ module.exports = class Assert {
message || `Expected selector '${selector}' to return one element`);
assert.equal(this.browser.activeElement, elements[0],
message || `Expected element '${selector}' to have the focus'`);
} else {
} else
assert.equal(this.browser.activeElement, this.browser.body,
message || "Expected no element to have focus");
}
message || 'Expected no element to have focus');
}


Expand All @@ -227,22 +226,20 @@ module.exports = class Assert {
// asserts that the expression evaluates to (JS) true.
evaluate(expression, expected, message) {
const actual = this.browser.evaluate(expression);
if (arguments.length === 1) {
if (arguments.length === 1)
assert(actual);
} else {
else
assertMatch(actual, expected, message);
}
}

// Asserts that the global (window) property name has the expected value.
global(name, expected, message) {
const actual = this.browser.window[name];
if (arguments.length === 1) {
if (arguments.length === 1)
assert(actual);
} else {
else
assertMatch(actual, expected,
message || `Expected global ${name} to have the value '${expected}', found '${actual}'`);
}
}

};
Expand Down
2 changes: 1 addition & 1 deletion src/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = class Cookies extends Array {
// domain - Set from hostname
// path - Set from pathname
update(httpHeader, domain, path) {
// One Set-Cookie is a string, multiple is an array
// One Set-Cookie is a string, multiple is an array
const cookies = isArray(httpHeader) ? httpHeader : [httpHeader];
cookies
.map(cookie => Cookie.parse(cookie))
Expand Down
Loading

0 comments on commit 41807a3

Please sign in to comment.