-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## Do not use `cy.pause` command | ||
|
||
It is recommended to remove [cy.pause](https://on.cypress.io/pause) command before committing the specs to avoid other developers getting unexpected results. | ||
|
||
Invalid: | ||
|
||
```js | ||
cy.pause(); | ||
``` | ||
|
||
Valid: | ||
|
||
```js | ||
// only the parent cy.pause command is detected | ||
cy.get('selector').pause(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict' | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: 'Disallow using of \'cy.pause\' calls', | ||
category: 'Possible Errors', | ||
recommended: false, | ||
}, | ||
fixable: null, // or "code" or "whitespace" | ||
schema: [], | ||
messages: { | ||
unexpected: 'Do not use cy.pause command', | ||
}, | ||
}, | ||
|
||
create (context) { | ||
|
||
// variables should be defined here | ||
|
||
//---------------------------------------------------------------------- | ||
// Helpers | ||
//---------------------------------------------------------------------- | ||
function isCallingPause (node) { | ||
return node.callee && | ||
node.callee.property && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name === 'pause' | ||
} | ||
|
||
function isCypressCall (node) { | ||
return node.callee && | ||
node.callee.type === 'MemberExpression' && | ||
node.callee.object.type === 'Identifier' && | ||
node.callee.object.name === 'cy' | ||
} | ||
|
||
//---------------------------------------------------------------------- | ||
// Public | ||
//---------------------------------------------------------------------- | ||
|
||
return { | ||
|
||
CallExpression (node) { | ||
if (isCypressCall(node) && isCallingPause(node)) { | ||
context.report({ node, messageId: 'unexpected' }) | ||
} | ||
}, | ||
|
||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict' | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
const rule = require('../../../lib/rules/no-pause') | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
|
||
const errors = [{ messageId: 'unexpected' }] | ||
const parserOptions = { ecmaVersion: 2018 } | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
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 }, | ||
], | ||
}) |