Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into no-unnecessary-waiting-support-import-bind…
…ings
- Loading branch information
Showing
9 changed files
with
96 additions
and
2 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,12 @@ | ||
name: 'Add issue/PR to Triage Board' | ||
on: | ||
issues: | ||
types: | ||
- opened | ||
pull_request_target: | ||
types: | ||
- opened | ||
jobs: | ||
add-to-triage-project-board: | ||
uses: cypress-io/cypress/.github/workflows/triage_add_to_project.yml@develop | ||
secrets: inherit |
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,9 @@ | ||
name: 'Handle Comment Workflow' | ||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
jobs: | ||
closed-issue-comment: | ||
uses: cypress-io/cypress/.github/workflows/triage_handle_new_comments.yml@develop | ||
secrets: inherit |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
## No Assigning Return Values | ||
## No Unnecessary Waiting | ||
|
||
See [the Cypress Best Practices guide](https://on.cypress.io/best-practices#Unnecessary-Waiting). |
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,3 @@ | ||
## Unsafe to chain command | ||
|
||
See [retry-ability guide](https://docs.cypress.io/guides/core-concepts/retry-ability#Actions-should-be-at-the-end-of-chains-not-the-middle). |
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,47 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: 'Actions should be in the end of chains, not in the middle', | ||
category: 'Possible Errors', | ||
recommended: true, | ||
url: 'https://docs.cypress.io/guides/core-concepts/retry-ability#Actions-should-be-at-the-end-of-chains-not-the-middle', | ||
}, | ||
schema: [], | ||
messages: { | ||
unexpected: 'It is unsafe to chain further commands that rely on the subject after this command. It is best to split the chain, chaining again from `cy.` in a next command line.', | ||
}, | ||
}, | ||
create (context) { | ||
return { | ||
CallExpression (node) { | ||
if (isRootCypress(node) && isActionUnsafeToChain(node) && node.parent.type === 'MemberExpression') { | ||
context.report({ node, messageId: 'unexpected' }) | ||
} | ||
}, | ||
} | ||
}, | ||
} | ||
|
||
function isRootCypress (node) { | ||
while (node.type === 'CallExpression') { | ||
if (node.callee.type !== 'MemberExpression') return false | ||
|
||
if (node.callee.object.type === 'Identifier' && | ||
node.callee.object.name === 'cy') { | ||
return true | ||
} | ||
|
||
node = node.callee.object | ||
} | ||
|
||
return false | ||
} | ||
|
||
function isActionUnsafeToChain (node) { | ||
// commands listed in the documentation with text: 'It is unsafe to chain further commands that rely on the subject after xxx' | ||
const unsafeToChainActions = ['blur', 'clear', 'click', 'check', 'dblclick', 'each', 'focus', 'rightclick', 'screenshot', 'scrollIntoView', 'scrollTo', 'select', 'selectFile', 'spread', 'submit', 'type', 'trigger', 'uncheck', 'within'] | ||
|
||
return node.callee && node.callee.property && node.callee.property.type === 'Identifier' && unsafeToChainActions.includes(node.callee.property.name) | ||
} |
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,20 @@ | ||
'use strict' | ||
|
||
const rule = require('../../../lib/rules/unsafe-to-chain-command') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
const ruleTester = new RuleTester() | ||
|
||
const errors = [{ messageId: 'unexpected' }] | ||
const parserOptions = { ecmaVersion: 6 } | ||
|
||
ruleTester.run('action-ends-chain', rule, { | ||
valid: [ | ||
{ code: 'cy.get("new-todo").type("todo A{enter}"); cy.get("new-todo").type("todo B{enter}"); cy.get("new-todo").should("have.class", "active");', parserOptions }, | ||
], | ||
|
||
invalid: [ | ||
{ code: 'cy.get("new-todo").type("todo A{enter}").should("have.class", "active");', parserOptions, errors }, | ||
{ code: 'cy.get("new-todo").type("todo A{enter}").type("todo B{enter}");', parserOptions, errors }, | ||
], | ||
}) |