-
Notifications
You must be signed in to change notification settings - Fork 89
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
5 changed files
with
105 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Disallow using `cy.debug()` calls (`cypress/no-debug`) | ||
|
||
<!-- end auto-generated rule header --> | ||
It is recommended to remove any [cy.debug](https://on.cypress.io/debug) commands before committing specs to avoid other developers getting unexpected results. | ||
|
||
## Rule Details | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
cy.debug(); | ||
cy.get('selector').debug(); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
cy.get('selector') | ||
``` |
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
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,61 @@ | ||
'use strict' | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = { | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'disallow using `cy.debug()` calls', | ||
category: 'Possible Errors', | ||
recommended: false, | ||
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-debug.md', | ||
}, | ||
fixable: null, // or "code" or "whitespace" | ||
schema: [], | ||
messages: { | ||
unexpected: 'Do not use cy.debug command', | ||
}, | ||
}, | ||
|
||
create (context) { | ||
|
||
// variables should be defined here | ||
|
||
//---------------------------------------------------------------------- | ||
// Helpers | ||
//---------------------------------------------------------------------- | ||
function isCallingDebug (node) { | ||
return node.callee && | ||
node.callee.property && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name === 'debug' | ||
} | ||
|
||
function isCypressCall (node) { | ||
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 | ||
//---------------------------------------------------------------------- | ||
|
||
return { | ||
|
||
CallExpression (node) { | ||
if (isCypressCall(node) && isCallingDebug(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,23 @@ | ||
'use strict' | ||
|
||
const rule = require('../../../lib/rules/no-debug') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
const errors = [{ messageId: 'unexpected' }] | ||
|
||
ruleTester.run('no-debug', rule, { | ||
|
||
valid: [ | ||
{ code: `debug()` }, | ||
{ code: `cy.get('button').dblclick()` }, | ||
], | ||
|
||
invalid: [ | ||
{ code: `cy.debug()`, errors }, | ||
{ code: `cy.debug({ log: false })`, errors }, | ||
{ code: `cy.get('button').debug()`, errors }, | ||
{ code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).debug()`, errors } | ||
], | ||
}) |