eslint-plugin-cypress 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{.eslintrc.json → .eslintrc.js} +5 -15
- package/.husky/pre-commit +0 -3
- package/README.md +18 -12
- package/docs/rules/assertion-before-screenshot.md +6 -3
- package/docs/rules/no-assigning-return-values.md +6 -1
- package/docs/rules/no-async-before.md +4 -4
- package/docs/rules/no-async-tests.md +6 -3
- package/docs/rules/no-force.md +4 -7
- package/docs/rules/no-pause.md +7 -4
- package/docs/rules/no-unnecessary-waiting.md +6 -1
- package/docs/rules/require-data-selectors.md +12 -6
- package/docs/rules/unsafe-to-chain-command.md +16 -1
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{
|
|
1
|
+
module.exports = {
|
|
2
2
|
"env": {
|
|
3
3
|
"node": true,
|
|
4
4
|
"es6": true
|
|
@@ -15,21 +15,11 @@
|
|
|
15
15
|
"plugin:mocha/recommended"
|
|
16
16
|
],
|
|
17
17
|
"rules": {
|
|
18
|
-
"eslint-plugin/require-meta-docs-url":
|
|
19
|
-
"error",
|
|
20
|
-
{
|
|
21
|
-
"pattern": "https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md"
|
|
22
|
-
}
|
|
23
|
-
],
|
|
18
|
+
"eslint-plugin/require-meta-docs-url":
|
|
19
|
+
["error", { "pattern": "https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md" }],
|
|
24
20
|
"eslint-plugin/require-meta-docs-description": "error",
|
|
25
|
-
"n/no-extraneous-require":
|
|
26
|
-
"error",
|
|
27
|
-
{
|
|
28
|
-
"allowModules": [
|
|
29
|
-
"jest-config"
|
|
30
|
-
]
|
|
31
|
-
}
|
|
32
|
-
],
|
|
21
|
+
"n/no-extraneous-require":
|
|
22
|
+
["error", { "allowModules": ["jest-config"] }],
|
|
33
23
|
"no-redeclare": "off",
|
|
34
24
|
"mocha/no-mocha-arrows": "off",
|
|
35
25
|
"mocha/no-setup-in-describe": "off"
|
package/.husky/pre-commit
CHANGED
package/README.md
CHANGED
|
@@ -115,18 +115,24 @@ For more, see the [ESLint rules](https://eslint.org/docs/user-guide/configuring/
|
|
|
115
115
|
|
|
116
116
|
These rules enforce some of the [best practices recommended for using Cypress](https://on.cypress.io/best-practices).
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
|
124
|
-
|
|
|
125
|
-
|
|
|
126
|
-
|
|
|
127
|
-
|
|
|
128
|
-
|
|
|
129
|
-
|
|
|
118
|
+
<!-- begin auto-generated rules list -->
|
|
119
|
+
|
|
120
|
+
💼 Configurations enabled in.\
|
|
121
|
+
✅ Set in the `recommended` configuration.
|
|
122
|
+
|
|
123
|
+
| Name | Description | 💼 |
|
|
124
|
+
| :----------------------------------------------------------------------- | :--------------------------------------------------------- | :- |
|
|
125
|
+
| [assertion-before-screenshot](docs/rules/assertion-before-screenshot.md) | require screenshots to be preceded by an assertion | |
|
|
126
|
+
| [no-assigning-return-values](docs/rules/no-assigning-return-values.md) | disallow assigning return values of `cy` calls | ✅ |
|
|
127
|
+
| [no-async-before](docs/rules/no-async-before.md) | disallow using `async`/`await` in Cypress `before` methods | |
|
|
128
|
+
| [no-async-tests](docs/rules/no-async-tests.md) | disallow using `async`/`await` in Cypress test cases | ✅ |
|
|
129
|
+
| [no-force](docs/rules/no-force.md) | disallow using `force: true` with action commands | |
|
|
130
|
+
| [no-pause](docs/rules/no-pause.md) | disallow using `cy.pause()` calls | |
|
|
131
|
+
| [no-unnecessary-waiting](docs/rules/no-unnecessary-waiting.md) | disallow waiting for arbitrary time periods | ✅ |
|
|
132
|
+
| [require-data-selectors](docs/rules/require-data-selectors.md) | require `data-*` attribute selectors | |
|
|
133
|
+
| [unsafe-to-chain-command](docs/rules/unsafe-to-chain-command.md) | disallow actions within chains | ✅ |
|
|
134
|
+
|
|
135
|
+
<!-- end auto-generated rules list -->
|
|
130
136
|
|
|
131
137
|
## Mocha and Chai
|
|
132
138
|
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
# Require screenshots to be preceded by an assertion (`cypress/assertion-before-screenshot`)
|
|
2
2
|
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
3
4
|
If you take screenshots without assertions then you may get different screenshots depending on timing.
|
|
4
5
|
|
|
5
6
|
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.
|
|
6
7
|
|
|
8
|
+
## Rule Details
|
|
9
|
+
|
|
7
10
|
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.
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
Examples of **incorrect** code for this rule:
|
|
10
13
|
|
|
11
14
|
```js
|
|
12
15
|
cy.visit('myUrl');
|
|
13
16
|
cy.screenshot();
|
|
14
17
|
```
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
Examples of **correct** code for this rule:
|
|
17
20
|
|
|
18
21
|
```js
|
|
19
22
|
cy.visit('myUrl');
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# Disallow assigning return values of `cy` calls (`cypress/no-assigning-return-values`)
|
|
2
|
+
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
|
4
|
+
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
6
|
+
## Further Reading
|
|
2
7
|
|
|
3
8
|
See [the Cypress Best Practices guide](https://on.cypress.io/best-practices#Assigning-Return-Values).
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Disallow using `async`/`await` in Cypress `before` methods (`cypress/no-async-before`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
4
|
+
Cypress commands that return a promise may cause side effects in `before`/`beforeEach` hooks, possibly causing unexpected behavior.
|
|
4
5
|
|
|
5
6
|
## Rule Details
|
|
6
7
|
|
|
@@ -38,12 +39,11 @@ describe('my feature', () => {
|
|
|
38
39
|
// other operations
|
|
39
40
|
})
|
|
40
41
|
})
|
|
41
|
-
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
## When Not To Use It
|
|
45
45
|
|
|
46
|
-
If there are genuine use-cases for using `async/await` in your before then you may not want to include this rule (or at least demote it to a warning).
|
|
46
|
+
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).
|
|
47
47
|
|
|
48
48
|
## Further Reading
|
|
49
49
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Disallow using `async`/`await` in Cypress test cases (`cypress/no-async-tests`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
|
4
|
+
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
6
|
+
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.
|
|
7
|
+
An `async` function returns a promise under the hood, so a test using an `async` function will also error.
|
|
4
8
|
|
|
5
9
|
## Rule Details
|
|
6
10
|
|
|
@@ -38,7 +42,6 @@ describe('my feature', () => {
|
|
|
38
42
|
// other operations
|
|
39
43
|
})
|
|
40
44
|
})
|
|
41
|
-
|
|
42
45
|
```
|
|
43
46
|
|
|
44
47
|
## When Not To Use It
|
package/docs/rules/no-force.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Disallow using `force: true` with action commands (`cypress/no-force`)
|
|
2
2
|
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
3
4
|
Using `force: true` on inputs appears to be confusing rather than helpful.
|
|
4
5
|
It usually silences the actual problem instead of providing a way to overcome it.
|
|
5
6
|
See [Cypress Core Concepts](https://docs.cypress.io/guides/core-concepts/interacting-with-elements.html#Forcing).
|
|
@@ -8,15 +9,15 @@ If enabling this rule, it's recommended to set the severity to `warn`.
|
|
|
8
9
|
|
|
9
10
|
## Rule Details
|
|
10
11
|
|
|
11
|
-
This rule
|
|
12
|
+
This rule disallows using the `force` option on:[`.click()`](https://on.cypress.io/click),
|
|
12
13
|
[`.dblclick()`](https://on.cypress.io/dblclick), [`.type()`](https://on.cypress.io/type),
|
|
13
14
|
[`.rightclick()`](https://on.cypress.io/rightclick), [`.select()`](https://on.cypress.io/select),
|
|
14
15
|
[`.focus()`](https://on.cypress.io/focus), [`.check()`](https://on.cypress.io/check),
|
|
15
16
|
and [`.trigger()`](https://on.cypress.io/trigger).
|
|
17
|
+
|
|
16
18
|
Examples of **incorrect** code for this rule:
|
|
17
19
|
|
|
18
20
|
```js
|
|
19
|
-
|
|
20
21
|
cy.get('button').click({force: true})
|
|
21
22
|
cy.get('button').dblclick({force: true})
|
|
22
23
|
cy.get('input').type('somth', {force: true})
|
|
@@ -26,13 +27,11 @@ cy.get('input').rightclick({force: true})
|
|
|
26
27
|
cy.get('input').check({force: true})
|
|
27
28
|
cy.get('input').select({force: true})
|
|
28
29
|
cy.get('input').focus({force: true})
|
|
29
|
-
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
Examples of **correct** code for this rule:
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
|
-
|
|
36
35
|
cy.get('button').click()
|
|
37
36
|
cy.get('button').click({multiple: true})
|
|
38
37
|
cy.get('button').dblclick()
|
|
@@ -42,10 +41,8 @@ cy.get('input').rightclick({anyoption: true})
|
|
|
42
41
|
cy.get('input').check()
|
|
43
42
|
cy.get('input').select()
|
|
44
43
|
cy.get('input').focus()
|
|
45
|
-
|
|
46
44
|
```
|
|
47
45
|
|
|
48
|
-
|
|
49
46
|
## When Not To Use It
|
|
50
47
|
|
|
51
48
|
If you don't mind using `{ force: true }` with action commands, then turn this rule off.
|
package/docs/rules/no-pause.md
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
# Disallow using `cy.pause()` calls (`cypress/no-pause`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
4
|
+
It is recommended to remove any [cy.pause](https://on.cypress.io/pause) commands before committing specs to avoid other developers getting unexpected results.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
## Rule Details
|
|
7
|
+
|
|
8
|
+
Examples of **incorrect** code for this rule:
|
|
6
9
|
|
|
7
10
|
```js
|
|
8
11
|
cy.pause();
|
|
9
12
|
```
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
Examples of **correct** code for this rule:
|
|
12
15
|
|
|
13
16
|
```js
|
|
14
17
|
// only the parent cy.pause command is detected
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# Disallow waiting for arbitrary time periods (`cypress/no-unnecessary-waiting`)
|
|
2
|
+
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
|
4
|
+
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
6
|
+
## Further Reading
|
|
2
7
|
|
|
3
8
|
See [the Cypress Best Practices guide](https://on.cypress.io/best-practices#Unnecessary-Waiting).
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
only allow `cy.get` to allow selectors that target `data-*` attributes
|
|
1
|
+
# Require `data-*` attribute selectors (`cypress/require-data-selectors`)
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
4
|
+
Require `cy.get` to use only selectors that target `data-*` attributes.
|
|
5
5
|
|
|
6
6
|
> Note: If you use this rule, consider only using the `warn` error level, since using `data-*` attribute selectors may not always be possible.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
## Rule Details
|
|
9
|
+
|
|
10
|
+
Examples of **incorrect** code for this rule:
|
|
9
11
|
|
|
10
|
-
examples of **incorrect** code with `require-data-selectors`:
|
|
11
12
|
```js
|
|
12
13
|
cy.get(".a")
|
|
13
14
|
cy.get('[daedta-cy=submit]').click()
|
|
@@ -16,8 +17,13 @@ cy.get(".btn-large").click()
|
|
|
16
17
|
cy.get(".btn-.large").click()
|
|
17
18
|
```
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
Examples of **correct** code for this rule:
|
|
21
|
+
|
|
20
22
|
```js
|
|
21
23
|
cy.get('[data-cy=submit]').click()
|
|
22
24
|
cy.get('[data-QA=submit]')
|
|
23
25
|
```
|
|
26
|
+
|
|
27
|
+
## Further Reading
|
|
28
|
+
|
|
29
|
+
See [the Cypress Best Practices guide](https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements).
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
# Disallow actions within chains (`cypress/unsafe-to-chain-command`)
|
|
2
|
+
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
|
4
|
+
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
6
|
+
### Options
|
|
7
|
+
|
|
8
|
+
<!-- begin auto-generated rule options list -->
|
|
9
|
+
|
|
10
|
+
| Name | Description | Type | Default |
|
|
11
|
+
| :-------- | :---------------------------------------------------------- | :---- | :------ |
|
|
12
|
+
| `methods` | An additional list of methods to check for unsafe chaining. | Array | `[]` |
|
|
13
|
+
|
|
14
|
+
<!-- end auto-generated rule options list -->
|
|
15
|
+
|
|
16
|
+
## Further Reading
|
|
2
17
|
|
|
3
18
|
See [retry-ability guide](https://docs.cypress.io/guides/core-concepts/retry-ability#Actions-should-be-at-the-end-of-chains-not-the-middle).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-cypress",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "An ESLint plugin for projects using Cypress",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Cypress-io",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"eslint-plugin-eslint-plugin": "^6.0.0",
|
|
30
30
|
"eslint-plugin-mocha": "^10.4.3",
|
|
31
31
|
"eslint-plugin-n": "^17.2.1",
|
|
32
|
-
"husky": "^
|
|
32
|
+
"husky": "^9.0.11",
|
|
33
33
|
"jest": "^29.7.0",
|
|
34
|
-
"semantic-release": "
|
|
34
|
+
"semantic-release": "23.0.8"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"lint": "eslint \"*.js\" \"**/**/*.js\"",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"start": "npm run test-watch",
|
|
41
41
|
"test": "jest",
|
|
42
42
|
"test-watch": "jest --watchAll",
|
|
43
|
-
"prepare": "husky
|
|
43
|
+
"prepare": "husky"
|
|
44
44
|
}
|
|
45
45
|
}
|