Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: apply no-pause rule recursively #189

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}
],
})