Skip to content

Commit

Permalink
feat(rules): add 'missing-wait-message' rule
Browse files Browse the repository at this point in the history
  • Loading branch information
alecxe committed Jan 31, 2016
1 parent d317a9f commit a62bc46
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This plugin ships with a default configuration for each rule:
Rule | Default | Options
---- | ------- | -------
[missing-perform][] | 2 |

[missing-wait-message][] | 1 |

For example, the `missing-perform` rule is enabled by default and will cause
ESLint to throw an error (with an exit code of `1`) when triggered.
Expand All @@ -51,6 +51,7 @@ rules:
See [configuring rules][] for more information.

[missing-perform]: docs/rules/missing-perform.md
[missing-wait-message]: docs/rules/missing-wait-message.md
[configuring rules]: http://eslint.org/docs/user-guide/configuring#configuring-rules

## Author
Expand Down
22 changes: 22 additions & 0 deletions docs/rules/missing-wait-message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Missing wait timeout message in `browser.wait()` (missing-wait-message)

Ensure the timeout message is set when `browser.wait()` is called.

## Rule details

This rule triggers a warning if there is no message in case `browser.wait()` timeouts.
Having explicit timeout messages helps in debugging and troubleshooting the test failures.

The following patterns are considered warnings:

```js
browser.wait(EC.presenceOf(elm), 5000);
browser.wait(EC.visibilityOf(elm), 5000);
```

The following patterns are not warnings:

```js
browser.wait(EC.presenceOf(elm), 5000, "The user menu is not present");
browser.wait(EC.elementToBeClickable(elm), 5000, "The submit button has not become clickable. Watch for the modal popup not to be opened.");
```
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
'missing-perform': require('./lib/rules/missing-perform')
},
rulesConfig: {
'missing-perform': 2
'missing-perform': 2,
'missing-wait-message': 1
}
}
19 changes: 19 additions & 0 deletions lib/rules/missing-wait-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

/**
* @fileoverview Missing wait timeout message in browser.wait() (missing-wait-message)
* @author Alexander Afanasyev
*/

module.exports = function (context) {
return {
'CallExpression': function (node) {
var objectName = node.callee.object.name
var propertyName = node.callee.property.name

if (propertyName === 'wait' && objectName === 'browser' && node.arguments.length < 3) {
context.report(node, 'No timeout message provided for browser.wait()')
}
}
}
}
32 changes: 32 additions & 0 deletions test/rules/missing-wait-message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict'

var rule = require('../../lib/rules/missing-wait-message')
var RuleTester = require('eslint').RuleTester

var eslintTester = new RuleTester()

eslintTester.run('missing-wait-message', rule, {
valid: [
'browser.wait(EC.presenceOf(elm), 5000, \'The user menu is not present\');',
'browser.wait(EC.elementToBeClickable(elm), 5000, \'The submit button has not become clickable. Watch for the modal popup not to be opened\');'
],

invalid: [
{
code: 'browser.wait(EC.presenceOf(elm), 5000);',
errors: [
{
message: 'No timeout message provided for browser.wait()'
}
]
},
{
code: 'browser.wait(EC.visibilityOf(elm), 5000);',
errors: [
{
message: 'No timeout message provided for browser.wait()'
}
]
}
]
})

0 comments on commit a62bc46

Please sign in to comment.