Skip to content

Commit

Permalink
feat(rules): add 'no-browser-driver' rule
Browse files Browse the repository at this point in the history
  • Loading branch information
eLRuLL committed Dec 22, 2016
1 parent 42c0e87 commit feb2d08
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var noArrayFinderMethods = require('./lib/rules/no-array-finder-methods')
var validLocatorType = require('./lib/rules/valid-locator-type')
var noCompoundClasses = require('./lib/rules/no-compound-classes')
var useCountMethod = require('./lib/rules/use-count-method')
var noBrowserDriver = require('./lib/rules/no-browser-driver')

module.exports = {
rules: {
Expand Down Expand Up @@ -62,7 +63,8 @@ module.exports = {
'no-array-finder-methods': noArrayFinderMethods,
'valid-locator-type': validLocatorType,
'no-compound-classes': noCompoundClasses,
'use-count-method': useCountMethod
'use-count-method': useCountMethod,
'no-browser-driver': noBrowserDriver
},
configs: {
recommended: {
Expand Down Expand Up @@ -96,7 +98,8 @@ module.exports = {
'protractor/no-angular-attributes': 1,
'protractor/use-count-method': 1,
'protractor/use-promise-all': 0,
'protractor/by-css-shortcut': 0
'protractor/by-css-shortcut': 0,
'protractor/no-browser-driver': 0
},
globals: {
'browser': false,
Expand Down
27 changes: 27 additions & 0 deletions lib/rules/no-browser-driver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

module.exports = {
meta: {
schema: []
},

create: function (context) {
// console.log(context)
return {
'MemberExpression': function (node) {
var object = node.object
if (object.name === 'browser') {
// when trying `var d = browser.driver;`
object = node
}
if (object.object && object.object.name === 'browser' &&
object.property && object.property.name === 'driver') {
context.report({
node: node,
message: 'Unexpected use of browser.driver instead of browser'
})
}
}
}
}
}
46 changes: 46 additions & 0 deletions test/rules/no-browser-driver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict'

var rule = require('../../lib/rules/no-browser-driver')
var RuleTester = require('eslint').RuleTester
var eslintTester = new RuleTester()

eslintTester.run('no-browser-driver', rule, {
valid: [
'browser.get();',
'browser.get("mypage");',
'browser.sleep(1000);',
'browser.getTitle();',
'browser.method(function() {});',
'var test = browser.get("MYPAGE");',
'var test = browser.attribute;'
],

invalid: [
{
code: 'browser.driver.sleep(2000);',
errors: [{
message: 'Unexpected use of browser.driver instead of browser'
}]
},
{
code: 'var test = browser.driver.getTitle();',
errors: [
{
message: 'Unexpected use of browser.driver instead of browser'
}
]
},
{
code: 'var test = browser.driver.attribute;',
errors: [{
message: 'Unexpected use of browser.driver instead of browser'
}]
},
{
code: 'var driver = browser.driver;',
errors: [{
message: 'Unexpected use of browser.driver instead of browser'
}]
}
]
})

0 comments on commit feb2d08

Please sign in to comment.