From f6ab851ac37f44fc6b08bce3d26105eef651ba2e Mon Sep 17 00:00:00 2001 From: Marketionist Date: Mon, 4 Dec 2017 07:51:14 -0400 Subject: [PATCH 1/4] Enabled semicolons and strict in .eslintrc.json --- .eslintrc.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index f170a39..214f589 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -130,7 +130,7 @@ "yoda": [2, "never", { "exceptRange": true }], // Strict Mode - "strict": [2, "global"], + "strict": [0, "global"], // Variables "init-declarations": 0, @@ -197,7 +197,7 @@ "quotes": [2, "single", "avoid-escape"], "require-jsdoc": 1, "semi-spacing": [2, {"before": false, "after": true}], - "semi": [0, "always"], + "semi": [2, "always"], "sort-vars": 0, "keyword-spacing": 2, "space-before-blocks": 2, From df07db0221f6539e8c2aa01c1afdfe880220276f Mon Sep 17 00:00:00 2001 From: Marketionist Date: Mon, 4 Dec 2017 07:59:41 -0400 Subject: [PATCH 2/4] Added semicolons and strict to files --- index.js | 14 +++++++------- src/steps/given.js | 19 ++++++++++--------- src/steps/then.js | 19 ++++++++++--------- test/wdio.conf.js | 21 ++++++++++----------- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index 0df09c9..7cdce3b 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,13 @@ -'use strict' +'use strict'; -const fs = require('fs') -const files = fs.readdirSync('./src/steps') +const fs = require('fs'); +const files = fs.readdirSync('./src/steps'); files.forEach((f) => { - const path = `./src/steps/${f}` - const fileSteps = require(path) + const path = `./src/steps/${f}`; + const fileSteps = require(path); if (typeof fileSteps === 'function') { - fileSteps.apply(this) + fileSteps.apply(this); } -}) +}); diff --git a/src/steps/given.js b/src/steps/given.js index 2884dcc..966953d 100644 --- a/src/steps/given.js +++ b/src/steps/given.js @@ -1,9 +1,10 @@ -/* eslint no-undef: 0 */ +'use strict'; + /* eslint new-cap: 0 */ -const { defineSupportCode } = require('cucumber') -const { dictionaryObject, getDictionaryObject } = require('../helpers/objects.processor') -const { _r } = require('../helpers/utils') +const { defineSupportCode } = require('cucumber'); +const { dictionaryObject, getDictionaryObject } = require('../helpers/objects.processor'); +const { _r } = require('../helpers/utils'); module.exports = function () { defineSupportCode(({ Given }) => { @@ -13,10 +14,10 @@ module.exports = function () { * The URL to navigate to * @type {String} or {DictionaryObject} */ - const url = getDictionaryObject.call(this, urlDictionary) + const url = getDictionaryObject.call(this, urlDictionary); - browser.url(url) - }) + browser.url(url); + }); - }) -} + }); +}; diff --git a/src/steps/then.js b/src/steps/then.js index 618a4f0..2518167 100644 --- a/src/steps/then.js +++ b/src/steps/then.js @@ -1,9 +1,10 @@ -/* eslint no-undef: 0 */ +'use strict'; + /* eslint new-cap: 0 */ -const { defineSupportCode } = require('cucumber') -const { pageObject, getPageObject } = require('../helpers/objects.processor') -const { _r } = require('../helpers/utils') +const { defineSupportCode } = require('cucumber'); +const { pageObject, getPageObject } = require('../helpers/objects.processor'); +const { _r } = require('../helpers/utils'); module.exports = function () { defineSupportCode(({ Then }) => { @@ -13,10 +14,10 @@ module.exports = function () { * The element should be present * @type {PageObject} */ - const locator = getPageObject(object) + const locator = getPageObject(object); - browser.$(locator).waitForExist() - }) + browser.$(locator).waitForExist(); + }); - }) -} + }); +}; diff --git a/test/wdio.conf.js b/test/wdio.conf.js index 338bf23..a5873bc 100644 --- a/test/wdio.conf.js +++ b/test/wdio.conf.js @@ -1,7 +1,7 @@ -/* eslint-disable */ +/* eslint max-len: 0 */ +/* eslint no-unused-vars: 0 */ exports.config = { - // // ================== // Specify Test Files @@ -146,9 +146,8 @@ exports.config = { strict: false, // fail if there are any undefined or pending steps tags: [], // (expression) only execute the features or scenarios with tags matching the expression timeout: 20000, // timeout for step definitions - ignoreUndefinedDefinitions: false, // Enable this config to treat undefined definitions as warnings. + ignoreUndefinedDefinitions: false // Enable this config to treat undefined definitions as warnings. }, - // // ===== // Hooks @@ -191,17 +190,17 @@ exports.config = { global.pages = { main: require('./features/page_objects/main') - } + }; global.id = { value: '', regenerate: () => this.value === (new Date()).getTime(), getId: () => this.value - } + }; - global.objectsProcessor = { } + global.objectsProcessor = { }; - }, + } /** * Runs before a WebdriverIO command gets executed. * @param {String} commandName hook command name @@ -209,7 +208,7 @@ exports.config = { */ // beforeCommand: function (commandName, args) { // }, - + /** * Runs before a Cucumber feature * @param {Object} feature feature details @@ -246,7 +245,7 @@ exports.config = { */ // afterFeature: function (feature) { // }, - + /** * Runs after a WebdriverIO command gets executed * @param {String} commandName hook command name @@ -281,4 +280,4 @@ exports.config = { */ // onComplete: function(exitCode, config, capabilities) { // } -} +}; From 444dcf498feebaa44dbc10f7c0eab1f4ffcca193 Mon Sep 17 00:00:00 2001 From: Marketionist Date: Mon, 4 Dec 2017 08:23:43 -0400 Subject: [PATCH 3/4] Added semicolons and strict to more files --- src/helpers/objects.processor.js | 90 ++++++++++++++-------------- src/helpers/utils.js | 12 ++-- test/features/page_objects/main.js | 8 ++- test/mocha/objects.processor.spec.js | 70 +++++++++++----------- test/wdio.conf.js | 5 +- 5 files changed, 98 insertions(+), 87 deletions(-) diff --git a/src/helpers/objects.processor.js b/src/helpers/objects.processor.js index d4a64a0..86f3c59 100644 --- a/src/helpers/objects.processor.js +++ b/src/helpers/objects.processor.js @@ -1,106 +1,108 @@ +'use strict'; + /* eslint no-param-reassign: 0*/ /* eslint no-undef: 0 */ -const { _r } = require('./utils') +const { _r } = require('./utils'); -const dynamicId = '$dynamicId$' -const regDynamicId = '\\$dynamicId\\$' +const dynamicId = '$dynamicId$'; +const regDynamicId = '\\$dynamicId\\$'; // Can come from applysteps ?? -const pageObject = '([a-zA-Z0-9_-]+ from [a-zA-Z0-9_-]+ page)' -const pageObjectsParts = '^([a-zA-Z0-9_-]+) from ([a-zA-Z0-9_-]+) page$' +const pageObject = '([a-zA-Z0-9_-]+ from [a-zA-Z0-9_-]+ page)'; +const pageObjectsParts = '^([a-zA-Z0-9_-]+) from ([a-zA-Z0-9_-]+) page$'; -const dictionaryObject = '([a-zA-Z0-9_-]+ from [a-zA-Z0-9_-]+ dictionary|"[^"]*")' -const dictionaryObjectsParts = '^(?:([a-zA-Z0-9_-]+) from ([a-zA-Z0-9_-]+) dictionary|"([^"]*)")$' +const dictionaryObject = '([a-zA-Z0-9_-]+ from [a-zA-Z0-9_-]+ dictionary|"[^"]*")'; +const dictionaryObjectsParts = '^(?:([a-zA-Z0-9_-]+) from ([a-zA-Z0-9_-]+) dictionary|"([^"]*)")$'; // Todo do we need this in csp-qa function injectInto(locator, injection) { - const lastInjectionSymbol = injection.slice(-1) - const lastLocatorSumbol = locator.slice(-1) + const lastInjectionSymbol = injection.slice(-1); + const lastLocatorSumbol = locator.slice(-1); if (lastInjectionSymbol !== ']') { // Add ']' to the end of injection only if missing (for backward compatibility) - injection += ']' + injection += ']'; } if (lastLocatorSumbol === ')') { // If our locator ends with round brackets - return injectInto(locator.replace(/\)$/, ''), injection) + ')' + return injectInto(locator.replace(/\)$/, ''), injection) + ')'; } if (lastLocatorSumbol === ']') { if (locator.match(/\[[0-9]+\]$/)) { // Locator ends with brackets, which contain some xpath num - const nums = locator.match(/\[[0-9]+\]$/)[0] - const body = locator.replace(/\[[0-9]+\]$/, '') + const nums = locator.match(/\[[0-9]+\]$/)[0]; + const body = locator.replace(/\[[0-9]+\]$/, ''); - return injectInto(body, injection) + nums + return injectInto(body, injection) + nums; } - return locator.substring(0, locator.length - 1) + ' and ' + injection + return locator.substring(0, locator.length - 1) + ' and ' + injection; } - return locator + '[' + injection + return locator + '[' + injection; } function pageObjectGetter(str) { - const match = _r(pageObjectsParts).exec(str) + const match = _r(pageObjectsParts).exec(str); if (!match) { - throw new Error(`Was unable to find Page Object for "${str}"`) + throw new Error(`Was unable to find Page Object for "${str}"`); } if (match[1]) { - const page = match[2] - const object = match[1] + const page = match[2]; + const object = match[1]; if (!pages[page]) { - throw new Error(`"${page}" page is missing`) + throw new Error(`"${page}" page is missing`); } if (!pages[page][object]) { - throw new Error(`"${object}" page object is missing for the "${page}" page`) + throw new Error(`"${object}" page object is missing for the "${page}" page`); } - return pages[page][object] + return pages[page][object]; } - throw new Error(`Unknown Page Object type for "${str}"`) + throw new Error(`Unknown Page Object type for "${str}"`); } function getPageObject(str) { - const pageObjectGetterFunc = objectsProcessor.pageObjectGetter || pageObjectGetter - const value = pageObjectGetterFunc(str) - const idValue = value.replace(_r(regDynamicId, 'g'), id.getId()) + const pageObjectGetterFunc = objectsProcessor.pageObjectGetter || pageObjectGetter; + const value = pageObjectGetterFunc(str); + const idValue = value.replace(_r(regDynamicId, 'g'), id.getId()); const injection = 'not(ancestor-or-self::*[contains(@style,"visibility: hidden;") ' + - 'or contains(@style,"display: none") or contains(@class,"x-hide-offsets")])' - const injectedvalue = injectInto(idValue, injection) + 'or contains(@style,"display: none") or contains(@class,"x-hide-offsets")])'; + const injectedValue = injectInto(idValue, injection); - return injectedvalue + return injectedValue; } function dicionaryGetter(str) { - const match = _r(dictionaryObjectsParts).exec(str) + const match = _r(dictionaryObjectsParts).exec(str); if (!match) { - throw new Error(`Was unable to find Dictionary Object type for "${str}"`) + throw new Error(`Was unable to find Dictionary Object type for "${str}"`); } if (match[1]) { - const dictionary = match[2] - const object = match[1] + const dictionary = match[2]; + const object = match[1]; if (!pages[dictionary]) { - throw new Error(`"${dictionary}" page is missing`) + throw new Error(`"${dictionary}" page is missing`); } if (!pages[dictionary][object]) { - throw new Error(`"${object}" page object is missing for the "${dictionary}" page`) + throw new Error(`"${object}" page object is missing for the "${dictionary}" page`); } - return pages[dictionary][object] + return pages[dictionary][object]; } if (match[3] !== undefined) { - return match[3] + return match[3]; } - throw new Error(`Unknown Dictionary Object type for "${str}"`) + throw new Error(`Unknown Dictionary Object type for "${str}"`); } function getDictionaryObject(str) { - const dicionaryGetterFunc = objectsProcessor.dicionaryGetter || dicionaryGetter - const value = dicionaryGetterFunc(str) - const idValue = value.replace(_r(regDynamicId, 'g'), id.getId()) + const dicionaryGetterFunc = objectsProcessor.dicionaryGetter || dicionaryGetter; + const value = dicionaryGetterFunc(str); + const idValue = value.replace(_r(regDynamicId, 'g'), id.getId()); - return idValue + return idValue; } module.exports = { @@ -110,4 +112,4 @@ module.exports = { injectInto, getPageObject, getDictionaryObject -} +}; diff --git a/src/helpers/utils.js b/src/helpers/utils.js index b7894e8..7d5b5a6 100644 --- a/src/helpers/utils.js +++ b/src/helpers/utils.js @@ -1,12 +1,14 @@ +'use strict'; + const escapeRegExp = function (str) { - return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\$&') -} + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\$&'); +}; const _r = function (str, flags) { - return new RegExp(escapeRegExp(str), flags) -} + return new RegExp(escapeRegExp(str), flags); +}; module.exports = { escapeRegExp, _r -} +}; diff --git a/test/features/page_objects/main.js b/test/features/page_objects/main.js index 035b6ec..d315d96 100644 --- a/test/features/page_objects/main.js +++ b/test/features/page_objects/main.js @@ -1,5 +1,7 @@ -let e = {} +'use strict'; -e.txtHeader = '//*[@id="header"]' +let e = {}; -module.exports = e +e.txtHeader = '//*[@id="header"]'; + +module.exports = e; diff --git a/test/mocha/objects.processor.spec.js b/test/mocha/objects.processor.spec.js index 3ff8d81..39745d4 100644 --- a/test/mocha/objects.processor.spec.js +++ b/test/mocha/objects.processor.spec.js @@ -1,4 +1,6 @@ -const { expect } = require('chai') +'use strict'; + +const { expect } = require('chai'); const { injectInto, @@ -7,10 +9,10 @@ const { getPageObject, getDictionaryObject, dynamicId -} = require('../../src/helpers/objects.processor') -const { _r } = require('../../src/helpers/utils') +} = require('../../src/helpers/objects.processor'); +const { _r } = require('../../src/helpers/utils'); -const realId = 12345 +const realId = 12345; global.pages = { main: { @@ -19,13 +21,13 @@ global.pages = { book: { word: `dictionaryObject${dynamicId}` } -} +}; global.id = { getId: () => realId -} +}; -global.objectsProcessor = { } +global.objectsProcessor = {}; describe('injectInto', () => { const data = [ @@ -33,14 +35,14 @@ describe('injectInto', () => { { locator: '//a', injection: '@class="b"', result: '//a[@class="b"]' }, { locator: '//a[@id=1]', injection: '@class="b"', result: '//a[@id=1 and @class="b"]' }, { locator: '(//a)[1]', injection: '@class="b"]', result: '(//a[@class="b"])[1]' } - ] + ]; data.forEach((d) => { it(`should get "${d.result}" string from "${d.locator}" and "${d.injection}" injection`, () => { - expect(injectInto(d.locator, d.injection)).to.be.equals(d.result) - }) - }) -}) + expect(injectInto(d.locator, d.injection)).to.be.equals(d.result); + }); + }); +}); describe('getPageObject', () => { const data = [ @@ -50,23 +52,23 @@ describe('getPageObject', () => { result: `//div[@id='${realId}' and not(ancestor-or-self::*[contains(@style,"visibility: hidden;") ` + 'or contains(@style,"display: none") or contains(@class,"x-hide-offsets")])]' } - ] + ]; data.forEach((d) => { - const { step, regExp, result } = d + const { step, regExp, result } = d; it(`should correctly get pageObject from the <<${step}>> step`, (next) => { - const match = step.match(regExp) + const match = step.match(regExp); - expect(match).to.be.an('array') - const strPageObject = match[1] - const pageObjectVal = getPageObject(strPageObject) + expect(match).to.be.an('array'); + const strPageObject = match[1]; + const pageObjectVal = getPageObject(strPageObject); - expect(pageObjectVal).to.be.equals(result) - next() - }) - }) -}) + expect(pageObjectVal).to.be.equals(result); + next(); + }); + }); +}); describe('getDictionaryObject', () => { const data = [ @@ -80,20 +82,20 @@ describe('getDictionaryObject', () => { regExp: _r(`When I write ${dictionaryObject}`), result: `dictionaryObject${realId}` } - ] + ]; data.forEach((d) => { - const { step, regExp, result } = d + const { step, regExp, result } = d; it(`should correctly get dictionaryObject from the <<${step}>> step`, (next) => { - const match = step.match(regExp) + const match = step.match(regExp); - expect(match).to.be.an('array') - const strDictionaryObject = match[1] - const dictionaryObjectVal = getDictionaryObject(strDictionaryObject) + expect(match).to.be.an('array'); + const strDictionaryObject = match[1]; + const dictionaryObjectVal = getDictionaryObject(strDictionaryObject); - expect(dictionaryObjectVal).to.be.equals(result) - next() - }) - }) -}) + expect(dictionaryObjectVal).to.be.equals(result); + next(); + }); + }); +}); diff --git a/test/wdio.conf.js b/test/wdio.conf.js index a5873bc..8e0427a 100644 --- a/test/wdio.conf.js +++ b/test/wdio.conf.js @@ -1,5 +1,8 @@ +'use strict'; + /* eslint max-len: 0 */ /* eslint no-unused-vars: 0 */ +/* eslint no-multi-spaces: 0 */ exports.config = { // @@ -198,7 +201,7 @@ exports.config = { getId: () => this.value }; - global.objectsProcessor = { }; + global.objectsProcessor = {}; } /** From 50a0793f175a62212695fb4ad592888f41d271a5 Mon Sep 17 00:00:00 2001 From: Marketionist Date: Tue, 5 Dec 2017 08:28:20 -0400 Subject: [PATCH 4/4] Enabled strict errors in eslint --- .eslintrc.json | 2 +- src/helpers/objects.processor.js | 2 -- src/helpers/utils.js | 2 -- src/steps/given.js | 2 -- src/steps/then.js | 2 -- test/features/page_objects/main.js | 2 -- test/mocha/objects.processor.spec.js | 2 -- test/wdio.conf.js | 2 -- 8 files changed, 1 insertion(+), 15 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 214f589..38d45b4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -130,7 +130,7 @@ "yoda": [2, "never", { "exceptRange": true }], // Strict Mode - "strict": [0, "global"], + "strict": [2, "global"], // Variables "init-declarations": 0, diff --git a/src/helpers/objects.processor.js b/src/helpers/objects.processor.js index 86f3c59..c8fbda0 100644 --- a/src/helpers/objects.processor.js +++ b/src/helpers/objects.processor.js @@ -1,5 +1,3 @@ -'use strict'; - /* eslint no-param-reassign: 0*/ /* eslint no-undef: 0 */ diff --git a/src/helpers/utils.js b/src/helpers/utils.js index 7d5b5a6..f1b512f 100644 --- a/src/helpers/utils.js +++ b/src/helpers/utils.js @@ -1,5 +1,3 @@ -'use strict'; - const escapeRegExp = function (str) { return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\$&'); }; diff --git a/src/steps/given.js b/src/steps/given.js index 966953d..36bbf7c 100644 --- a/src/steps/given.js +++ b/src/steps/given.js @@ -1,5 +1,3 @@ -'use strict'; - /* eslint new-cap: 0 */ const { defineSupportCode } = require('cucumber'); diff --git a/src/steps/then.js b/src/steps/then.js index 2518167..7953899 100644 --- a/src/steps/then.js +++ b/src/steps/then.js @@ -1,5 +1,3 @@ -'use strict'; - /* eslint new-cap: 0 */ const { defineSupportCode } = require('cucumber'); diff --git a/test/features/page_objects/main.js b/test/features/page_objects/main.js index d315d96..e6cf562 100644 --- a/test/features/page_objects/main.js +++ b/test/features/page_objects/main.js @@ -1,5 +1,3 @@ -'use strict'; - let e = {}; e.txtHeader = '//*[@id="header"]'; diff --git a/test/mocha/objects.processor.spec.js b/test/mocha/objects.processor.spec.js index 39745d4..f57a6dc 100644 --- a/test/mocha/objects.processor.spec.js +++ b/test/mocha/objects.processor.spec.js @@ -1,5 +1,3 @@ -'use strict'; - const { expect } = require('chai'); const { diff --git a/test/wdio.conf.js b/test/wdio.conf.js index 8e0427a..47023c8 100644 --- a/test/wdio.conf.js +++ b/test/wdio.conf.js @@ -1,5 +1,3 @@ -'use strict'; - /* eslint max-len: 0 */ /* eslint no-unused-vars: 0 */ /* eslint no-multi-spaces: 0 */