This commit is contained in:
2024-11-28 23:08:17 +01:00
parent 8895fde030
commit 0dda8e760c
16116 changed files with 2866428 additions and 71 deletions

View File

@@ -0,0 +1,25 @@
# Require screenshots to be preceded by an assertion (`cypress/assertion-before-screenshot`)
<!-- end auto-generated rule header -->
If you take screenshots without assertions then you may get different screenshots depending on timing.
For example, if clicking a button makes some network calls and upon success, renders something, then the screenshot may sometimes have the new render and sometimes not.
## Rule Details
This rule checks there is an assertion making sure your application state is correct before doing a screenshot. This makes sure the result of the screenshot will be consistent.
Examples of **incorrect** code for this rule:
```js
cy.visit('myUrl');
cy.screenshot();
```
Examples of **correct** code for this rule:
```js
cy.visit('myUrl');
cy.get('[data-test-id="my-element"]').should('be.visible');
cy.screenshot();
```

View File

@@ -0,0 +1,8 @@
# Disallow assigning return values of `cy` calls (`cypress/no-assigning-return-values`)
💼 This rule is enabled in the ✅ `recommended` config.
<!-- end auto-generated rule header -->
## Further Reading
See [the Cypress Best Practices guide](https://on.cypress.io/best-practices#Assigning-Return-Values).

View File

@@ -0,0 +1,51 @@
# Disallow using `async`/`await` in Cypress `before` methods (`cypress/no-async-before`)
<!-- end auto-generated rule header -->
Cypress commands that return a promise may cause side effects in `before`/`beforeEach` hooks, possibly causing unexpected behavior.
## Rule Details
This rule disallows using `async` `before` and `beforeEach` functions.
Examples of **incorrect** code for this rule:
```js
describe('my feature', () => {
before('my test case', async () => {
await cy.get('.myClass')
// other operations
})
})
```
```js
describe('my feature', () => {
before('my test case', async () => {
cy
.get('.myClass')
.click()
await someAsyncFunction()
})
})
```
Examples of **correct** code for this rule:
```js
describe('my feature', () => {
before('my test case', () => {
cy.get('.myClass')
// other operations
})
})
```
## When Not To Use It
If there are genuine use-cases for using `async/await` in your `before` hooks then you may not want to include this rule (or at least demote it to a warning).
## Further Reading
- [Mixing Async and Sync code](https://on.cypress.io/guides/core-concepts/introduction-to-cypress#Mixing-Async-and-Sync-code)
- [Commands Are Asynchronous](https://on.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Asynchronous)

View File

@@ -0,0 +1,54 @@
# Disallow using `async`/`await` in Cypress test cases (`cypress/no-async-tests`)
💼 This rule is enabled in the ✅ `recommended` config.
<!-- end auto-generated rule header -->
Cypress tests [that return a promise will error](https://docs.cypress.io/guides/references/error-messages.html#Cypress-detected-that-you-returned-a-promise-from-a-command-while-also-invoking-one-or-more-cy-commands-in-that-promise) and cannot run successfully.
An `async` function returns a promise under the hood, so a test using an `async` function will also error.
## Rule Details
This rule disallows using `async` test functions.
Examples of **incorrect** code for this rule:
```js
describe('my feature', () => {
it('my test case', async () => {
await cy.get('.myClass')
// other operations
})
})
```
```js
describe('my feature', () => {
it('my test case', async () => {
cy
.get('.myClass')
.click()
await someAsyncFunction()
})
})
```
Examples of **correct** code for this rule:
```js
describe('my feature', () => {
it('my test case', () => {
cy.get('.myClass')
// other operations
})
})
```
## When Not To Use It
If there are genuine use-cases for using `async/await` in your test cases then you may not want to include this rule (or at least demote it to a warning).
## Further Reading
- [Mixing Async and Sync code](https://on.cypress.io/guides/core-concepts/introduction-to-cypress#Mixing-Async-and-Sync-code)
- [Commands Are Asynchronous](https://on.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Asynchronous)

View File

@@ -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')
```

View File

@@ -0,0 +1,48 @@
# Disallow using `force: true` with action commands (`cypress/no-force`)
<!-- end auto-generated rule header -->
Using `force: true` on inputs appears to be confusing rather than helpful.
It usually silences the actual problem instead of providing a way to overcome it.
See [Cypress Core Concepts](https://docs.cypress.io/guides/core-concepts/interacting-with-elements.html#Forcing).
If enabling this rule, it's recommended to set the severity to `warn`.
## Rule Details
This rule disallows using the `force` option on:[`.click()`](https://on.cypress.io/click),
[`.dblclick()`](https://on.cypress.io/dblclick), [`.type()`](https://on.cypress.io/type),
[`.rightclick()`](https://on.cypress.io/rightclick), [`.select()`](https://on.cypress.io/select),
[`.focus()`](https://on.cypress.io/focus), [`.check()`](https://on.cypress.io/check),
and [`.trigger()`](https://on.cypress.io/trigger).
Examples of **incorrect** code for this rule:
```js
cy.get('button').click({force: true})
cy.get('button').dblclick({force: true})
cy.get('input').type('somth', {force: true})
cy.get('div').find('.foo').find('.bar').trigger('change', {force: true})
cy.get('input').trigger('click', {force: true})
cy.get('input').rightclick({force: true})
cy.get('input').check({force: true})
cy.get('input').select({force: true})
cy.get('input').focus({force: true})
```
Examples of **correct** code for this rule:
```js
cy.get('button').click()
cy.get('button').click({multiple: true})
cy.get('button').dblclick()
cy.get('input').type('somth')
cy.get('input').trigger('click', {anyoption: true})
cy.get('input').rightclick({anyoption: true})
cy.get('input').check()
cy.get('input').select()
cy.get('input').focus()
```
## When Not To Use It
If you don't mind using `{ force: true }` with action commands, then turn this rule off.

View File

@@ -0,0 +1,19 @@
# Disallow using `cy.pause()` calls (`cypress/no-pause`)
<!-- end auto-generated rule header -->
It is recommended to remove any [cy.pause](https://on.cypress.io/pause) commands before committing specs to avoid other developers getting unexpected results.
## Rule Details
Examples of **incorrect** code for this rule:
```js
cy.pause();
cy.get('selector').pause();
```
Examples of **correct** code for this rule:
```js
cy.get('selector')
```

View File

@@ -0,0 +1,8 @@
# Disallow waiting for arbitrary time periods (`cypress/no-unnecessary-waiting`)
💼 This rule is enabled in the ✅ `recommended` config.
<!-- end auto-generated rule header -->
## Further Reading
See [the Cypress Best Practices guide](https://on.cypress.io/best-practices#Unnecessary-Waiting).

View File

@@ -0,0 +1,29 @@
# Require `data-*` attribute selectors (`cypress/require-data-selectors`)
<!-- end auto-generated rule header -->
Require `cy.get` to use only selectors that target `data-*` attributes.
> Note: If you use this rule, consider only using the `warn` error level, since using `data-*` attribute selectors may not always be possible.
## Rule Details
Examples of **incorrect** code for this rule:
```js
cy.get(".a")
cy.get('[daedta-cy=submit]').click()
cy.get('[d-cy=submit]')
cy.get(".btn-large").click()
cy.get(".btn-.large").click()
```
Examples of **correct** code for this rule:
```js
cy.get('[data-cy=submit]').click()
cy.get('[data-QA=submit]')
```
## Further Reading
See [the Cypress Best Practices guide](https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements).

View File

@@ -0,0 +1,18 @@
# Disallow actions within chains (`cypress/unsafe-to-chain-command`)
💼 This rule is enabled in the ✅ `recommended` config.
<!-- end auto-generated rule header -->
### Options
<!-- begin auto-generated rule options list -->
| Name | Description | Type | Default |
| :-------- | :---------------------------------------------------------- | :---- | :------ |
| `methods` | An additional list of methods to check for unsafe chaining. | Array | `[]` |
<!-- end auto-generated rule options list -->
## Further Reading
See [retry-ability guide](https://docs.cypress.io/guides/core-concepts/retry-ability#Actions-should-be-at-the-end-of-chains-not-the-middle).