diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..1f6c6f3 --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,2 @@ +extends: + - './node_modules/mobify-code-style/es6/mobify-es6-react-a11y.yml' \ No newline at end of file diff --git a/commands/preview.js b/commands/preview.js index 47c4ca8..ca7f740 100644 --- a/commands/preview.js +++ b/commands/preview.js @@ -17,32 +17,31 @@ * @api commands */ -var qs = require('querystring'); +import qs from 'querystring' -exports.command = function(url, bundle, callback) { - var browser = this; +export const command = function(url, bundle = 'https://localhost:8443/loader.js', callback) { + const browser = this if (arguments.length < 2) { - throw new Error('Usage: browser.preview(url, bundle, callback)'); + throw new Error('Usage: browser.preview(url, bundle, callback)') } if (typeof bundle === 'function') { - callback = bundle; - bundle = null; + callback = bundle + bundle = null } - var bundleUrl = bundle || 'https://localhost:8443/loader.js'; + const params = qs.stringify({url, site_folder: bundle}) - var params = qs.stringify({'url': url, 'site_folder': bundleUrl}); - - return browser.url('https://preview.mobify.com?' + params) + return browser + .url(`https://preview.mobify.com?${params}`) .waitForElementPresent('#authorize', 10000, function() { - this.click('#authorize', function() { - browser.waitUntilMobified(10000, function(result) { + this.click('#authorize', () => { + browser.waitUntilMobified(10000, (result) => { if (typeof callback === 'function') { - callback.call(browser, result); + callback.call(browser, result) } - }); - }); - }); -}; + }) + }) + }) +} diff --git a/commands/triggerClick.js b/commands/triggerClick.js index e9654b6..b45cbb5 100644 --- a/commands/triggerClick.js +++ b/commands/triggerClick.js @@ -1,13 +1,13 @@ -exports.command = function(selector, callback) { - var client = this; +export const command = function(selector, callback) { + const client = this /* / Use Javascript's click when Selenium's does not register. */ - client.execute('document.querySelector("' + selector + '").click();', function(result) { + client.execute(`document.querySelector("${selector}").click();`, (result) => { if (typeof callback === 'function') { - callback.call(client, result); + callback.call(client, result) } - }); + }) - return this; -}; + return this +} diff --git a/package.json b/package.json index 9250cd1..b4f8b40 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,10 @@ "url": "https://github.com/mobify/nightwatch-commands/issues" }, "devDependencies": { + "eslint": "3.19.0", + "eslint-plugin-import": "2.2.0", + "eslint-plugin-jsx-a11y": "2.2.3", + "eslint-plugin-react": "6.10.3", "nightwatch": "0.9.8", "nodeunit": "0.8.4", "grunt": "0.4.5", @@ -20,7 +24,9 @@ }, "scripts": { "install": "node selenium/install.js", - "test": "./node_modules/.bin/grunt lint; ./node_modules/.bin/grunt test" + "test": "./node_modules/.bin/grunt lint; ./node_modules/.bin/grunt test", + "lint": "npm run lint:js", + "lint:js": "eslint '**/*.{js,jsx}'" }, "homepage": "https://github.com/mobify/nightwatch-commands", "dependencies": {