From d09fc7f5cb0fc70ddd21e21b348c50c09a66b03e Mon Sep 17 00:00:00 2001 From: jasecode Date: Mon, 16 Apr 2018 11:51:46 -0700 Subject: [PATCH 1/5] add es6 lint rules --- .eslintrc.yml | 2 ++ package.json | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .eslintrc.yml 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/package.json b/package.json index 8ce6938..27d6374 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": { From 2aad69bfe8cd9b8bebcb3ae25156c730ba7ae812 Mon Sep 17 00:00:00 2001 From: jasecode Date: Mon, 16 Apr 2018 14:11:29 -0700 Subject: [PATCH 2/5] es6 preview.js command --- commands/preview.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/commands/preview.js b/commands/preview.js index 47c4ca8..192c3d9 100644 --- a/commands/preview.js +++ b/commands/preview.js @@ -17,32 +17,33 @@ * @api commands */ -var qs = require('querystring'); +import qs from 'querystring' -exports.command = function(url, bundle, callback) { - var browser = this; +exports.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 bundleUrl = bundle || 'https://localhost:8443/loader.js' - var params = qs.stringify({'url': url, 'site_folder': bundleUrl}); + const params = qs.stringify({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) } - }); - }); - }); -}; + }) + }) + }) +} From e2d47eb4cc11e08991c9a7f267d5c0d8301e567d Mon Sep 17 00:00:00 2001 From: jasecode Date: Mon, 16 Apr 2018 14:34:54 -0700 Subject: [PATCH 3/5] es6 triggerClick command --- commands/triggerClick.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/commands/triggerClick.js b/commands/triggerClick.js index e9654b6..66afafd 100644 --- a/commands/triggerClick.js +++ b/commands/triggerClick.js @@ -1,13 +1,13 @@ exports.command = function(selector, callback) { - var client = this; + 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 +} From be3c2a0709b5ce57ab474df835a25af365168d67 Mon Sep 17 00:00:00 2001 From: jasecode Date: Mon, 16 Apr 2018 14:54:49 -0700 Subject: [PATCH 4/5] refactor preview.js --- commands/preview.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/commands/preview.js b/commands/preview.js index 192c3d9..d3e15bd 100644 --- a/commands/preview.js +++ b/commands/preview.js @@ -31,9 +31,7 @@ exports.command = function(url, bundle = 'https://localhost:8443/loader.js', cal bundle = null } - const bundleUrl = bundle || 'https://localhost:8443/loader.js' - - const params = qs.stringify({url, site_folder: bundleUrl}) + const params = qs.stringify({url, site_folder: bundle}) return browser .url(`https://preview.mobify.com?${params}`) From 5c15e291901c8e09cc0d735c6f2abe49aec24651 Mon Sep 17 00:00:00 2001 From: jasecode Date: Tue, 17 Apr 2018 13:55:39 -0700 Subject: [PATCH 5/5] PR Feedback --- commands/preview.js | 2 +- commands/triggerClick.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/preview.js b/commands/preview.js index d3e15bd..ca7f740 100644 --- a/commands/preview.js +++ b/commands/preview.js @@ -19,7 +19,7 @@ import qs from 'querystring' -exports.command = function(url, bundle = 'https://localhost:8443/loader.js', callback) { +export const command = function(url, bundle = 'https://localhost:8443/loader.js', callback) { const browser = this if (arguments.length < 2) { diff --git a/commands/triggerClick.js b/commands/triggerClick.js index 66afafd..b45cbb5 100644 --- a/commands/triggerClick.js +++ b/commands/triggerClick.js @@ -1,4 +1,4 @@ -exports.command = function(selector, callback) { +export const command = function(selector, callback) { const client = this /* / Use Javascript's click when Selenium's does not register.