eslint-plugin-cypress 3.0.3 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,11 +9,11 @@ Examples of **incorrect** code for this rule:
9
9
 
10
10
  ```js
11
11
  cy.pause();
12
+ cy.get('selector').pause();
12
13
  ```
13
14
 
14
15
  Examples of **correct** code for this rule:
15
16
 
16
17
  ```js
17
- // only the parent cy.pause command is detected
18
- cy.get('selector').pause();
18
+ cy.get('selector')
19
19
  ```
@@ -35,12 +35,15 @@ module.exports = {
35
35
  }
36
36
 
37
37
  function isCypressCall (node) {
38
- return node.callee &&
39
- node.callee.type === 'MemberExpression' &&
40
- node.callee.object.type === 'Identifier' &&
41
- node.callee.object.name === 'cy'
38
+ if (!node.callee || node.callee.type !== 'MemberExpression') {
39
+ return false;
40
+ }
41
+ if (node.callee.object.type === 'Identifier' && node.callee.object.name === 'cy') {
42
+ return true;
43
+ }
44
+ return isCypressCall(node.callee.object);
42
45
  }
43
-
46
+
44
47
  //----------------------------------------------------------------------
45
48
  // Public
46
49
  //----------------------------------------------------------------------
@@ -19,7 +19,7 @@ const unsafeToChainActions = [
19
19
  'check',
20
20
  'dblclick',
21
21
  'each',
22
- 'focus$',
22
+ 'focus',
23
23
  'rightclick',
24
24
  'screenshot',
25
25
  'scrollIntoView',
@@ -130,7 +130,7 @@ const isRootCypress = (node) => {
130
130
  */
131
131
  const isActionUnsafeToChain = (node, additionalMethods = []) => {
132
132
  const unsafeActionsRegex = new RegExp([
133
- ...unsafeToChainActions,
133
+ ...unsafeToChainActions.map((action) => `^${action}$`),
134
134
  ...additionalMethods.map((method) => method instanceof RegExp ? method.source : method),
135
135
  ].join('|'))
136
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-cypress",
3
- "version": "3.0.3",
3
+ "version": "3.1.1",
4
4
  "description": "An ESLint plugin for projects using Cypress",
5
5
  "main": "index.js",
6
6
  "author": "Cypress-io",
@@ -20,14 +20,18 @@ const ruleTester = new RuleTester()
20
20
  ruleTester.run('no-pause', rule, {
21
21
 
22
22
  valid: [
23
- // for now, we do not detect .pause() child command
24
- { code: `cy.get('button').pause()`, parserOptions },
25
23
  { code: `pause()`, parserOptions },
26
24
  { code: `cy.get('button').dblclick()`, parserOptions },
27
25
  ],
28
-
26
+
29
27
  invalid: [
30
28
  { code: `cy.pause()`, parserOptions, errors },
31
29
  { code: `cy.pause({ log: false })`, parserOptions, errors },
30
+ { code: `cy.get('button').pause()`, parserOptions, errors },
31
+ {
32
+ code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).pause()`,
33
+ parserOptions,
34
+ errors
35
+ }
32
36
  ],
33
37
  })
@@ -18,6 +18,10 @@ ruleTester.run('action-ends-chain', rule, {
18
18
  code: 'cy.focused().should("be.visible");',
19
19
  parserOptions,
20
20
  },
21
+ {
22
+ code: 'cy.submitBtn().click();',
23
+ parserOptions,
24
+ },
21
25
  ],
22
26
 
23
27
  invalid: [