Skip to content

Commit 87f35e0

Browse files
Merge pull request #189 from tom9744/user/tom9744/recursive-no-pause
feat: apply no-pause rule recursively
2 parents abb8591 + 8696387 commit 87f35e0

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

docs/rules/no-pause.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ Examples of **incorrect** code for this rule:
99

1010
```js
1111
cy.pause();
12+
cy.get('selector').pause();
1213
```
1314

1415
Examples of **correct** code for this rule:
1516

1617
```js
17-
// only the parent cy.pause command is detected
18-
cy.get('selector').pause();
18+
cy.get('selector')
1919
```

lib/rules/no-pause.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ module.exports = {
3535
}
3636

3737
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);
4245
}
43-
46+
4447
//----------------------------------------------------------------------
4548
// Public
4649
//----------------------------------------------------------------------

tests/lib/rules/no-pause.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ const ruleTester = new RuleTester()
2020
ruleTester.run('no-pause', rule, {
2121

2222
valid: [
23-
// for now, we do not detect .pause() child command
24-
{ code: `cy.get('button').pause()`, parserOptions },
2523
{ code: `pause()`, parserOptions },
2624
{ code: `cy.get('button').dblclick()`, parserOptions },
2725
],
28-
26+
2927
invalid: [
3028
{ code: `cy.pause()`, parserOptions, errors },
3129
{ 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+
}
3236
],
3337
})

0 commit comments

Comments
 (0)