File tree 4 files changed +108
-1
lines changed 4 files changed +108
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ You can add rules:
35
35
"cypress/no-unnecessary-waiting" : " error" ,
36
36
"cypress/assertion-before-screenshot" : " warn" ,
37
37
"cypress/no-force" : " warn" ,
38
- "cypress/no-async-tests" : " error"
38
+ "cypress/no-async-tests" : " error" ,
39
+ "cypress/no-pause" : " error"
39
40
}
40
41
}
41
42
```
@@ -123,6 +124,7 @@ Rules with a check mark (✅) are enabled by default while using the `plugin:cyp
123
124
| | [ no-force] ( ./docs/rules/no-force.md ) | Disallow using ` force: true ` with action commands |
124
125
| | [ assertion-before-screenshot] ( ./docs/rules/assertion-before-screenshot.md ) | Ensure screenshots are preceded by an assertion |
125
126
| | [ require-data-selectors] ( ./docs/rules/require-data-selectors.md ) | Only allow data-\* attribute selectors (require-data-selectors) |
127
+ | | [ no-pause] ( ./docs/rules/no-pause.md ) | Disallow ` cy.pause() ` parent command |
126
128
127
129
## Chai and ` no-unused-expressions `
128
130
Original file line number Diff line number Diff line change
1
+ ## Do not use ` cy.pause ` command
2
+
3
+ It is recommended to remove [ cy.pause] ( https://on.cypress.io/pause ) command before committing the specs to avoid other developers getting unexpected results.
4
+
5
+ Invalid:
6
+
7
+ ``` js
8
+ cy .pause ();
9
+ ```
10
+
11
+ Valid:
12
+
13
+ ``` js
14
+ // only the parent cy.pause command is detected
15
+ cy .get (' selector' ).pause ();
16
+ ```
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ //------------------------------------------------------------------------------
4
+ // Rule Definition
5
+ //------------------------------------------------------------------------------
6
+
7
+ module . exports = {
8
+ meta : {
9
+ docs : {
10
+ description : 'Disallow using of \'cy.pause\' calls' ,
11
+ category : 'Possible Errors' ,
12
+ recommended : false ,
13
+ } ,
14
+ fixable : null , // or "code" or "whitespace"
15
+ schema : [ ] ,
16
+ messages : {
17
+ unexpected : 'Do not use cy.pause command' ,
18
+ } ,
19
+ } ,
20
+
21
+ create ( context ) {
22
+
23
+ // variables should be defined here
24
+
25
+ //----------------------------------------------------------------------
26
+ // Helpers
27
+ //----------------------------------------------------------------------
28
+ function isCallingPause ( node ) {
29
+ return node . callee &&
30
+ node . callee . property &&
31
+ node . callee . property . type === 'Identifier' &&
32
+ node . callee . property . name === 'pause'
33
+ }
34
+
35
+ function isCypressCall ( node ) {
36
+ return node . callee &&
37
+ node . callee . type === 'MemberExpression' &&
38
+ node . callee . object . type === 'Identifier' &&
39
+ node . callee . object . name === 'cy'
40
+ }
41
+
42
+ //----------------------------------------------------------------------
43
+ // Public
44
+ //----------------------------------------------------------------------
45
+
46
+ return {
47
+
48
+ CallExpression ( node ) {
49
+ if ( isCypressCall ( node ) && isCallingPause ( node ) ) {
50
+ context . report ( { node, messageId : 'unexpected' } )
51
+ }
52
+ } ,
53
+
54
+ }
55
+ } ,
56
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ //------------------------------------------------------------------------------
4
+ // Requirements
5
+ //------------------------------------------------------------------------------
6
+
7
+ const rule = require ( '../../../lib/rules/no-pause' )
8
+
9
+ const RuleTester = require ( 'eslint' ) . RuleTester
10
+
11
+ const errors = [ { messageId : 'unexpected' } ]
12
+ const parserOptions = { ecmaVersion : 2018 }
13
+
14
+ //------------------------------------------------------------------------------
15
+ // Tests
16
+ //------------------------------------------------------------------------------
17
+
18
+ const ruleTester = new RuleTester ( )
19
+
20
+ ruleTester . run ( 'no-pause' , rule , {
21
+
22
+ valid : [
23
+ // for now, we do not detect .pause() child command
24
+ { code : `cy.get('button').pause()` , parserOptions } ,
25
+ { code : `pause()` , parserOptions } ,
26
+ { code : `cy.get('button').dblclick()` , parserOptions } ,
27
+ ] ,
28
+
29
+ invalid : [
30
+ { code : `cy.pause()` , parserOptions, errors } ,
31
+ { code : `cy.pause({ log: false })` , parserOptions, errors } ,
32
+ ] ,
33
+ } )
You can’t perform that action at this time.
0 commit comments