Skip to content

Commit

Permalink
Merge pull request #189 from tom9744/user/tom9744/recursive-no-pause
Browse files Browse the repository at this point in the history
feat: apply no-pause rule recursively
  • Loading branch information
jennifer-shehane authored May 3, 2024
2 parents abb8591 + 8696387 commit 87f35e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/rules/no-pause.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Examples of **incorrect** code for this rule:

```js
cy.pause();
cy.get('selector').pause();
```

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

```js
// only the parent cy.pause command is detected
cy.get('selector').pause();
cy.get('selector')
```
13 changes: 8 additions & 5 deletions lib/rules/no-pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ module.exports = {
}

function isCypressCall (node) {
return node.callee &&
node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
node.callee.object.name === 'cy'
if (!node.callee || node.callee.type !== 'MemberExpression') {
return false;
}
if (node.callee.object.type === 'Identifier' && node.callee.object.name === 'cy') {
return true;
}
return isCypressCall(node.callee.object);
}

//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
Expand Down
10 changes: 7 additions & 3 deletions tests/lib/rules/no-pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ const ruleTester = new RuleTester()
ruleTester.run('no-pause', rule, {

valid: [
// for now, we do not detect .pause() child command
{ code: `cy.get('button').pause()`, parserOptions },
{ code: `pause()`, parserOptions },
{ code: `cy.get('button').dblclick()`, parserOptions },
],

invalid: [
{ code: `cy.pause()`, parserOptions, errors },
{ code: `cy.pause({ log: false })`, parserOptions, errors },
{ code: `cy.get('button').pause()`, parserOptions, errors },
{
code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).pause()`,
parserOptions,
errors
}
],
})

0 comments on commit 87f35e0

Please sign in to comment.