eslint-plugin-cypress 3.0.1 → 3.0.2
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 +2 -1
- package/docs/rules/no-async-before.md +3 -4
- package/docs/rules/no-async-tests.md +2 -3
- package/lib/rules/assertion-before-screenshot.js +1 -1
- package/lib/rules/no-assigning-return-values.js +1 -1
- package/lib/rules/no-async-before.js +5 -2
- package/lib/rules/no-async-tests.js +5 -2
- package/lib/rules/no-force.js +1 -1
- package/lib/rules/no-pause.js +1 -1
- package/lib/rules/no-unnecessary-waiting.js +6 -2
- package/lib/rules/require-data-selectors.js +1 -1
- package/lib/rules/unsafe-to-chain-command.js +1 -1
- package/package.json +1 -1
package/.eslintrc.json
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"pattern": "https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md"
|
|
22
22
|
}
|
|
23
23
|
],
|
|
24
|
+
"eslint-plugin/require-meta-docs-description": "error",
|
|
24
25
|
"n/no-extraneous-require": [
|
|
25
26
|
"error",
|
|
26
27
|
{
|
|
@@ -34,6 +35,6 @@
|
|
|
34
35
|
"mocha/no-setup-in-describe": "off"
|
|
35
36
|
},
|
|
36
37
|
"parserOptions": {
|
|
37
|
-
"ecmaVersion":
|
|
38
|
+
"ecmaVersion": 2020
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Prevent using async/await in Cypress test cases (no-async-tests)
|
|
2
2
|
|
|
3
|
-
Cypress commands that return a promise may cause side effects in before/beforeEach hooks, possibly causing unexpected behavior.
|
|
3
|
+
Cypress commands that return a promise may cause side effects in before/beforeEach hooks, possibly causing unexpected behavior.
|
|
4
4
|
|
|
5
5
|
## Rule Details
|
|
6
6
|
|
|
@@ -47,6 +47,5 @@ If there are genuine use-cases for using `async/await` in your before then you m
|
|
|
47
47
|
|
|
48
48
|
## Further Reading
|
|
49
49
|
|
|
50
|
-
- [
|
|
51
|
-
- [Commands Are
|
|
52
|
-
- [Commands Are Not Promises](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Not-Promises)
|
|
50
|
+
- [Mixing Async and Sync code](https://on.cypress.io/guides/core-concepts/introduction-to-cypress#Mixing-Async-and-Sync-code)
|
|
51
|
+
- [Commands Are Asynchronous](https://on.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Asynchronous)
|
|
@@ -47,6 +47,5 @@ If there are genuine use-cases for using `async/await` in your test cases then y
|
|
|
47
47
|
|
|
48
48
|
## Further Reading
|
|
49
49
|
|
|
50
|
-
- [
|
|
51
|
-
- [Commands Are
|
|
52
|
-
- [Commands Are Not Promises](https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Not-Promises)
|
|
50
|
+
- [Mixing Async and Sync code](https://on.cypress.io/guides/core-concepts/introduction-to-cypress#Mixing-Async-and-Sync-code)
|
|
51
|
+
- [Commands Are Asynchronous](https://on.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Asynchronous)
|
|
@@ -18,7 +18,7 @@ module.exports = {
|
|
|
18
18
|
meta: {
|
|
19
19
|
type: 'problem',
|
|
20
20
|
docs: {
|
|
21
|
-
description: '
|
|
21
|
+
description: 'require screenshots to be preceded by an assertion',
|
|
22
22
|
category: 'Possible Errors',
|
|
23
23
|
recommended: false,
|
|
24
24
|
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/assertion-before-screenshot.md',
|
|
@@ -19,7 +19,7 @@ module.exports = {
|
|
|
19
19
|
meta: {
|
|
20
20
|
type: 'problem',
|
|
21
21
|
docs: {
|
|
22
|
-
description: '
|
|
22
|
+
description: 'disallow assigning return values of `cy` calls',
|
|
23
23
|
category: 'Possible Errors',
|
|
24
24
|
recommended: true,
|
|
25
25
|
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-assigning-return-values.md',
|
|
@@ -4,7 +4,7 @@ module.exports = {
|
|
|
4
4
|
meta: {
|
|
5
5
|
type: 'problem',
|
|
6
6
|
docs: {
|
|
7
|
-
description: '
|
|
7
|
+
description: 'disallow using `async`/`await` in Cypress `before` methods',
|
|
8
8
|
category: 'Possible Errors',
|
|
9
9
|
recommended: true,
|
|
10
10
|
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-async-before.md',
|
|
@@ -28,11 +28,14 @@ module.exports = {
|
|
|
28
28
|
&& node.arguments.length >= 2
|
|
29
29
|
&& node.arguments[1].async === true
|
|
30
30
|
}
|
|
31
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode()
|
|
31
32
|
|
|
32
33
|
return {
|
|
33
34
|
Identifier (node) {
|
|
34
35
|
if (node.name === 'cy' || node.name === 'Cypress') {
|
|
35
|
-
const ancestors =
|
|
36
|
+
const ancestors = sourceCode.getAncestors
|
|
37
|
+
? sourceCode.getAncestors(node)
|
|
38
|
+
: context.getAncestors()
|
|
36
39
|
const asyncTestBlocks = ancestors
|
|
37
40
|
.filter((n) => n.type === 'CallExpression')
|
|
38
41
|
.filter(isBeforeBlock)
|
|
@@ -4,7 +4,7 @@ module.exports = {
|
|
|
4
4
|
meta: {
|
|
5
5
|
type: 'problem',
|
|
6
6
|
docs: {
|
|
7
|
-
description: '
|
|
7
|
+
description: 'disallow using `async`/`await` in Cypress test cases',
|
|
8
8
|
category: 'Possible Errors',
|
|
9
9
|
recommended: true,
|
|
10
10
|
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-async-tests.md',
|
|
@@ -28,11 +28,14 @@ module.exports = {
|
|
|
28
28
|
&& node.arguments.length >= 2
|
|
29
29
|
&& node.arguments[1].async === true
|
|
30
30
|
}
|
|
31
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode()
|
|
31
32
|
|
|
32
33
|
return {
|
|
33
34
|
Identifier (node) {
|
|
34
35
|
if (node.name === 'cy' || node.name === 'Cypress') {
|
|
35
|
-
const ancestors =
|
|
36
|
+
const ancestors = sourceCode.getAncestors
|
|
37
|
+
? sourceCode.getAncestors(node)
|
|
38
|
+
: context.getAncestors()
|
|
36
39
|
const asyncTestBlocks = ancestors
|
|
37
40
|
.filter((n) => n.type === 'CallExpression')
|
|
38
41
|
.filter(isTestBlock)
|
package/lib/rules/no-force.js
CHANGED
|
@@ -8,7 +8,7 @@ module.exports = {
|
|
|
8
8
|
meta: {
|
|
9
9
|
type: 'suggestion',
|
|
10
10
|
docs: {
|
|
11
|
-
description: '
|
|
11
|
+
description: 'disallow using `force: true` with action commands',
|
|
12
12
|
category: 'Possible Errors',
|
|
13
13
|
recommended: false,
|
|
14
14
|
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-force.md',
|
package/lib/rules/no-pause.js
CHANGED
|
@@ -8,7 +8,7 @@ module.exports = {
|
|
|
8
8
|
meta: {
|
|
9
9
|
type: 'suggestion',
|
|
10
10
|
docs: {
|
|
11
|
-
description: '
|
|
11
|
+
description: 'disallow using `cy.pause()` calls',
|
|
12
12
|
category: 'Possible Errors',
|
|
13
13
|
recommended: false,
|
|
14
14
|
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-pause.md',
|
|
@@ -4,7 +4,7 @@ module.exports = {
|
|
|
4
4
|
meta: {
|
|
5
5
|
type: 'problem',
|
|
6
6
|
docs: {
|
|
7
|
-
description: '
|
|
7
|
+
description: 'disallow waiting for arbitrary time periods',
|
|
8
8
|
category: 'Possible Errors',
|
|
9
9
|
recommended: true,
|
|
10
10
|
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-unnecessary-waiting.md',
|
|
@@ -15,10 +15,14 @@ module.exports = {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
create (context) {
|
|
18
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode()
|
|
19
|
+
|
|
18
20
|
return {
|
|
19
21
|
CallExpression (node) {
|
|
20
22
|
if (isCallingCyWait(node)) {
|
|
21
|
-
const scope =
|
|
23
|
+
const scope = sourceCode.getScope
|
|
24
|
+
? sourceCode.getScope(node)
|
|
25
|
+
: context.getScope()
|
|
22
26
|
|
|
23
27
|
if (isIdentifierNumberConstArgument(node, scope) || isNumberArgument(node)) {
|
|
24
28
|
context.report({ node, messageId: 'unexpected' })
|
|
@@ -4,7 +4,7 @@ module.exports = {
|
|
|
4
4
|
meta: {
|
|
5
5
|
type: 'suggestion',
|
|
6
6
|
docs: {
|
|
7
|
-
description: '
|
|
7
|
+
description: 'require `data-*` attribute selectors',
|
|
8
8
|
category: 'Possible Errors',
|
|
9
9
|
recommended: false,
|
|
10
10
|
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/require-data-selectors.md',
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const { basename } = require('path')
|
|
4
4
|
|
|
5
5
|
const NAME = basename(__dirname)
|
|
6
|
-
const DESCRIPTION = '
|
|
6
|
+
const DESCRIPTION = 'disallow actions within chains'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Commands listed in the documentation with text: 'It is unsafe to chain further commands that rely on the subject after xxx.'
|