eslint-plugin-cypress 5.0.0 → 5.1.0
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/CONTRIBUTING.md +1 -1
- package/lib/flat.js +8 -8
- package/lib/rules/assertion-before-screenshot.js +21 -21
- package/lib/rules/no-assigning-return-values.js +4 -4
- package/lib/rules/no-async-before.js +10 -10
- package/lib/rules/no-async-tests.js +10 -10
- package/lib/rules/no-chained-get.js +32 -32
- package/lib/rules/no-debug.js +18 -19
- package/lib/rules/no-force.js +21 -24
- package/lib/rules/no-pause.js +18 -19
- package/lib/rules/no-unnecessary-waiting.js +13 -13
- package/lib/rules/no-xpath.js +10 -10
- package/lib/rules/require-data-selectors.js +14 -14
- package/lib/rules/unsafe-to-chain-command.js +13 -13
- package/package.json +10 -6
- package/.github/workflows/add-issue-triage-board.yml +0 -12
- package/.github/workflows/triage_closed_issue_comment.yml +0 -9
- package/.husky/pre-commit +0 -1
- package/.node-version +0 -1
- package/.nvmrc +0 -1
- package/ESLINTRC-CONFIG.md +0 -7
- package/FLAT-CONFIG.md +0 -3
- package/circle.yml +0 -137
- package/eslint.config.mjs +0 -26
- package/jest.config.js +0 -6
- package/test-project/README.md +0 -48
- package/test-project/cypress/e2e/1-getting-started/todo.cy.js +0 -143
- package/test-project/cypress/e2e/2-advanced-examples/actions.cy.js +0 -321
- package/test-project/cypress/e2e/2-advanced-examples/aliasing.cy.js +0 -39
- package/test-project/cypress/e2e/2-advanced-examples/assertions.cy.js +0 -176
- package/test-project/cypress/e2e/2-advanced-examples/connectors.cy.js +0 -98
- package/test-project/cypress/e2e/2-advanced-examples/cookies.cy.js +0 -118
- package/test-project/cypress/e2e/2-advanced-examples/cypress_api.cy.js +0 -185
- package/test-project/cypress/e2e/2-advanced-examples/files.cy.js +0 -85
- package/test-project/cypress/e2e/2-advanced-examples/location.cy.js +0 -32
- package/test-project/cypress/e2e/2-advanced-examples/misc.cy.js +0 -90
- package/test-project/cypress/e2e/2-advanced-examples/navigation.cy.js +0 -55
- package/test-project/cypress/e2e/2-advanced-examples/network_requests.cy.js +0 -163
- package/test-project/cypress/e2e/2-advanced-examples/querying.cy.js +0 -114
- package/test-project/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +0 -204
- package/test-project/cypress/e2e/2-advanced-examples/storage.cy.js +0 -117
- package/test-project/cypress/e2e/2-advanced-examples/traversal.cy.js +0 -121
- package/test-project/cypress/e2e/2-advanced-examples/utilities.cy.js +0 -107
- package/test-project/cypress/e2e/2-advanced-examples/viewport.cy.js +0 -58
- package/test-project/cypress/e2e/2-advanced-examples/waiting.cy.js +0 -30
- package/test-project/cypress/e2e/2-advanced-examples/window.cy.js +0 -22
- package/test-project/cypress/fixtures/example.json +0 -5
- package/test-project/cypress/support/commands.js +0 -25
- package/test-project/cypress/support/e2e.js +0 -17
- package/test-project/cypress.config.js +0 -9
- package/test-project/eslint-configs/eslint.default-deprecated.mjs +0 -11
- package/test-project/eslint-configs/eslint.default.mjs +0 -9
- package/test-project/eslint-configs/eslint.globals.mjs +0 -4
- package/test-project/eslint-configs/eslint.recommended.mjs +0 -9
- package/test-project/eslint.config.mjs +0 -9
- package/test-project/package.json +0 -9
- package/tests/config.js +0 -26
- package/tests/lib/rules/assertion-before-screenshot.js +0 -34
- package/tests/lib/rules/no-assigning-return-values.js +0 -37
- package/tests/lib/rules/no-async-before.js +0 -23
- package/tests/lib/rules/no-async-tests.js +0 -23
- package/tests/lib/rules/no-chained-get.js +0 -31
- package/tests/lib/rules/no-debug.js +0 -23
- package/tests/lib/rules/no-force.js +0 -39
- package/tests/lib/rules/no-pause.js +0 -23
- package/tests/lib/rules/no-unnecessary-waiting.js +0 -47
- package/tests/lib/rules/no-xpath.js +0 -30
- package/tests/lib/rules/require-data-selectors.js +0 -30
- package/tests/lib/rules/unsafe-to-chain-command.js +0 -34
package/lib/rules/no-xpath.js
CHANGED
|
@@ -6,7 +6,7 @@ module.exports = {
|
|
|
6
6
|
docs: {
|
|
7
7
|
description: 'disallow using `cy.xpath()` calls',
|
|
8
8
|
recommended: false,
|
|
9
|
-
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-xpath.md'
|
|
9
|
+
url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-xpath.md',
|
|
10
10
|
},
|
|
11
11
|
fixable: null, // Or `code` or `whitespace`
|
|
12
12
|
schema: [], // Add a schema if the rule has options
|
|
@@ -15,21 +15,21 @@ module.exports = {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
|
|
18
|
-
create
|
|
18
|
+
create(context) {
|
|
19
19
|
return {
|
|
20
|
-
CallExpression
|
|
20
|
+
CallExpression(node) {
|
|
21
21
|
if (isCallingCyXpath(node)) {
|
|
22
22
|
context.report({ node, messageId: 'unexpected' })
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
|
-
}
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
function isCallingCyXpath
|
|
30
|
-
return node.callee.type === 'MemberExpression'
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
function isCallingCyXpath(node) {
|
|
30
|
+
return node.callee.type === 'MemberExpression'
|
|
31
|
+
&& node.callee.object.type === 'Identifier'
|
|
32
|
+
&& node.callee.object.name === 'cy'
|
|
33
|
+
&& node.callee.property.type === 'Identifier'
|
|
34
|
+
&& node.callee.property.name === 'xpath'
|
|
35
35
|
}
|
|
@@ -15,9 +15,9 @@ module.exports = {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
|
|
18
|
-
create
|
|
18
|
+
create(context) {
|
|
19
19
|
return {
|
|
20
|
-
CallExpression
|
|
20
|
+
CallExpression(node) {
|
|
21
21
|
if (isCallingCyGet(node) && !isDataArgument(node)) {
|
|
22
22
|
context.report({ node, messageId: 'unexpected' })
|
|
23
23
|
}
|
|
@@ -26,23 +26,23 @@ module.exports = {
|
|
|
26
26
|
},
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function isCallingCyGet
|
|
30
|
-
return node.callee.type === 'MemberExpression'
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
function isCallingCyGet(node) {
|
|
30
|
+
return node.callee.type === 'MemberExpression'
|
|
31
|
+
&& node.callee.object.type === 'Identifier'
|
|
32
|
+
&& node.callee.object.name === 'cy'
|
|
33
|
+
&& node.callee.property.type === 'Identifier'
|
|
34
|
+
&& node.callee.property.name === 'get'
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function isDataArgument
|
|
38
|
-
return node.arguments.length > 0
|
|
39
|
-
(
|
|
40
|
-
(node.arguments[0].type === 'Literal' && isAliasOrDataSelector(String(node.arguments[0].value)))
|
|
41
|
-
(node.arguments[0].type === 'TemplateLiteral' && isAliasOrDataSelector(String(node.arguments[0].quasis[0].value.cooked)))
|
|
37
|
+
function isDataArgument(node) {
|
|
38
|
+
return node.arguments.length > 0
|
|
39
|
+
&& (
|
|
40
|
+
(node.arguments[0].type === 'Literal' && isAliasOrDataSelector(String(node.arguments[0].value)))
|
|
41
|
+
|| (node.arguments[0].type === 'TemplateLiteral' && isAliasOrDataSelector(String(node.arguments[0].quasis[0].value.cooked)))
|
|
42
42
|
)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function isAliasOrDataSelector
|
|
45
|
+
function isAliasOrDataSelector(selector) {
|
|
46
46
|
return ['[data-', '@'].some(function (validValue) {
|
|
47
47
|
return selector.startsWith(validValue)
|
|
48
48
|
})
|
|
@@ -82,15 +82,15 @@ module.exports = {
|
|
|
82
82
|
'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.',
|
|
83
83
|
},
|
|
84
84
|
},
|
|
85
|
-
create
|
|
85
|
+
create(context) {
|
|
86
86
|
const { methods } = getDefaultOptions(context)
|
|
87
87
|
|
|
88
88
|
return {
|
|
89
|
-
CallExpression
|
|
89
|
+
CallExpression(node) {
|
|
90
90
|
if (
|
|
91
|
-
isRootCypress(node)
|
|
92
|
-
isActionUnsafeToChain(node, methods)
|
|
93
|
-
node.parent.type === 'MemberExpression'
|
|
91
|
+
isRootCypress(node)
|
|
92
|
+
&& isActionUnsafeToChain(node, methods)
|
|
93
|
+
&& node.parent.type === 'MemberExpression'
|
|
94
94
|
) {
|
|
95
95
|
context.report({
|
|
96
96
|
node,
|
|
@@ -108,15 +108,15 @@ module.exports = {
|
|
|
108
108
|
*/
|
|
109
109
|
const isRootCypress = (node) => {
|
|
110
110
|
if (
|
|
111
|
-
node.type !== 'CallExpression'
|
|
112
|
-
node.callee.type !== 'MemberExpression'
|
|
111
|
+
node.type !== 'CallExpression'
|
|
112
|
+
|| node.callee.type !== 'MemberExpression'
|
|
113
113
|
) {
|
|
114
114
|
return false
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
if (
|
|
118
|
-
node.callee.object.type === 'Identifier'
|
|
119
|
-
node.callee.object.name === 'cy'
|
|
118
|
+
node.callee.object.type === 'Identifier'
|
|
119
|
+
&& node.callee.object.name === 'cy'
|
|
120
120
|
) {
|
|
121
121
|
return true
|
|
122
122
|
}
|
|
@@ -135,9 +135,9 @@ const isActionUnsafeToChain = (node, additionalMethods = []) => {
|
|
|
135
135
|
].join('|'))
|
|
136
136
|
|
|
137
137
|
return (
|
|
138
|
-
node.callee
|
|
139
|
-
node.callee.property
|
|
140
|
-
node.callee.property.type === 'Identifier'
|
|
141
|
-
unsafeActionsRegex.test(node.callee.property.name)
|
|
138
|
+
node.callee
|
|
139
|
+
&& node.callee.property
|
|
140
|
+
&& node.callee.property.type === 'Identifier'
|
|
141
|
+
&& unsafeActionsRegex.test(node.callee.property.name)
|
|
142
142
|
)
|
|
143
143
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-cypress",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "An ESLint plugin for projects using Cypress",
|
|
5
5
|
"main": "./lib/flat.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./lib/flat.js",
|
|
8
8
|
"./flat": "./lib/flat.js"
|
|
9
9
|
},
|
|
10
|
+
"files": [
|
|
11
|
+
"lib",
|
|
12
|
+
"docs",
|
|
13
|
+
"CONTRIBUTING.md"
|
|
14
|
+
],
|
|
10
15
|
"author": "Cypress-io",
|
|
11
16
|
"license": "MIT",
|
|
12
17
|
"keywords": [
|
|
@@ -29,20 +34,19 @@
|
|
|
29
34
|
"globals": "^16.2.0"
|
|
30
35
|
},
|
|
31
36
|
"devDependencies": {
|
|
37
|
+
"@stylistic/eslint-plugin": "^4.4.0",
|
|
32
38
|
"eslint": "^9.27.0",
|
|
33
39
|
"eslint-plugin-eslint-plugin": "^6.4.0",
|
|
34
40
|
"eslint-plugin-mocha": "^11.1.0",
|
|
35
41
|
"husky": "^9.1.7",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
42
|
+
"semantic-release": "24.2.5",
|
|
43
|
+
"vitest": "^3.1.4"
|
|
38
44
|
},
|
|
39
45
|
"scripts": {
|
|
40
46
|
"lint": "eslint",
|
|
41
47
|
"lint-fix": "eslint --fix",
|
|
42
48
|
"semantic-release": "semantic-release",
|
|
43
|
-
"
|
|
44
|
-
"test": "jest",
|
|
45
|
-
"test-watch": "jest --watchAll",
|
|
49
|
+
"test": "vitest run",
|
|
46
50
|
"prepare": "husky"
|
|
47
51
|
}
|
|
48
52
|
}
|
package/.husky/pre-commit
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
npm run lint
|
package/.node-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
22.16.0
|
package/.nvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
22.16.0
|
package/ESLINTRC-CONFIG.md
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# Cypress ESLint Plugin - Legacy Config
|
|
2
|
-
|
|
3
|
-
This document previously described how to use the Cypress ESLint Plugin (`eslint-plugin-cypress`) with an [ESLint legacy config environment](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated).
|
|
4
|
-
|
|
5
|
-
This form of configuration was deprecated with the release of ESLint `v9` and its use with `eslint-plugin-cypress` is no longer supported.
|
|
6
|
-
|
|
7
|
-
Users who were previously using a deprecated configuration environment should migrate to a [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files).
|
package/FLAT-CONFIG.md
DELETED
package/circle.yml
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
version: 2.1
|
|
2
|
-
|
|
3
|
-
executors:
|
|
4
|
-
docker-executor:
|
|
5
|
-
docker:
|
|
6
|
-
- image: cimg/node:22.16.0
|
|
7
|
-
resource_class: medium
|
|
8
|
-
|
|
9
|
-
workflows:
|
|
10
|
-
main:
|
|
11
|
-
jobs:
|
|
12
|
-
- lint
|
|
13
|
-
- test-v9
|
|
14
|
-
|
|
15
|
-
- build-test-project
|
|
16
|
-
- test-test-project:
|
|
17
|
-
matrix:
|
|
18
|
-
parameters:
|
|
19
|
-
eslint-version: ['9']
|
|
20
|
-
config-file: [
|
|
21
|
-
# configurations correspond to examples in README
|
|
22
|
-
'default',
|
|
23
|
-
'default-deprecated', # using deprecated /flat
|
|
24
|
-
'recommended',
|
|
25
|
-
'globals',
|
|
26
|
-
]
|
|
27
|
-
requires:
|
|
28
|
-
- build-test-project
|
|
29
|
-
- release:
|
|
30
|
-
requires:
|
|
31
|
-
- lint
|
|
32
|
-
- test-v9
|
|
33
|
-
- test-test-project
|
|
34
|
-
filters:
|
|
35
|
-
branches:
|
|
36
|
-
only:
|
|
37
|
-
- master
|
|
38
|
-
|
|
39
|
-
jobs:
|
|
40
|
-
lint:
|
|
41
|
-
executor: docker-executor
|
|
42
|
-
steps:
|
|
43
|
-
- checkout
|
|
44
|
-
- run:
|
|
45
|
-
name: Install dependencies
|
|
46
|
-
command: npm ci
|
|
47
|
-
- run:
|
|
48
|
-
name: Show ESLint version
|
|
49
|
-
command: npx eslint --version
|
|
50
|
-
- run:
|
|
51
|
-
name: Lint code
|
|
52
|
-
command: npm run lint
|
|
53
|
-
|
|
54
|
-
test-v9:
|
|
55
|
-
executor: docker-executor
|
|
56
|
-
steps:
|
|
57
|
-
- checkout
|
|
58
|
-
- run:
|
|
59
|
-
name: Install dependencies
|
|
60
|
-
command: npm ci
|
|
61
|
-
- run:
|
|
62
|
-
name: Install ESLint 9
|
|
63
|
-
command: npm install eslint@9
|
|
64
|
-
- run:
|
|
65
|
-
name: Show ESLint version
|
|
66
|
-
command: npx eslint --version
|
|
67
|
-
- run:
|
|
68
|
-
name: Test ESLint 9
|
|
69
|
-
command: npm test
|
|
70
|
-
|
|
71
|
-
build-test-project:
|
|
72
|
-
executor: docker-executor
|
|
73
|
-
steps:
|
|
74
|
-
- checkout
|
|
75
|
-
- run:
|
|
76
|
-
name: Install dependencies
|
|
77
|
-
command: npm ci
|
|
78
|
-
- run:
|
|
79
|
-
name: Build tarball
|
|
80
|
-
command: npm pack
|
|
81
|
-
- run:
|
|
82
|
-
name: Get version
|
|
83
|
-
command: |
|
|
84
|
-
echo "PLUGIN_VERSION=$(jq -r '.version' package.json)" >> $BASH_ENV
|
|
85
|
-
cp $BASH_ENV bash.env
|
|
86
|
-
- persist_to_workspace:
|
|
87
|
-
root: .
|
|
88
|
-
paths:
|
|
89
|
-
- eslint-plugin-cypress-*.tgz
|
|
90
|
-
- bash.env
|
|
91
|
-
|
|
92
|
-
test-test-project:
|
|
93
|
-
description: Run ESLint with different configurations
|
|
94
|
-
parameters:
|
|
95
|
-
eslint-version:
|
|
96
|
-
description: Version of ESLint to use
|
|
97
|
-
default: 'latest'
|
|
98
|
-
type: string
|
|
99
|
-
config-file:
|
|
100
|
-
description: Configuration file
|
|
101
|
-
default: 'default'
|
|
102
|
-
type: string
|
|
103
|
-
executor: docker-executor
|
|
104
|
-
working_directory: ./test-project
|
|
105
|
-
steps:
|
|
106
|
-
- checkout:
|
|
107
|
-
path: ../
|
|
108
|
-
- attach_workspace:
|
|
109
|
-
at: .
|
|
110
|
-
- run:
|
|
111
|
-
name: Get plugin version
|
|
112
|
-
command: |
|
|
113
|
-
cat bash.env >> $BASH_ENV
|
|
114
|
-
- run:
|
|
115
|
-
name: Install dependencies
|
|
116
|
-
command: |
|
|
117
|
-
npm install eslint@<< parameters.eslint-version>> ./eslint-plugin-cypress-$PLUGIN_VERSION.tgz -D
|
|
118
|
-
- run:
|
|
119
|
-
name: Display ESLint version
|
|
120
|
-
command: |
|
|
121
|
-
npx eslint --version
|
|
122
|
-
- run: echo Testing a << parameters.config-file >> configuration
|
|
123
|
-
- run:
|
|
124
|
-
name: Lint with example configuration
|
|
125
|
-
command: |
|
|
126
|
-
npx eslint --config ./eslint-configs/eslint.<< parameters.config-file >>.mjs .
|
|
127
|
-
|
|
128
|
-
release:
|
|
129
|
-
executor: docker-executor
|
|
130
|
-
steps:
|
|
131
|
-
- checkout
|
|
132
|
-
- run:
|
|
133
|
-
name: Install dependencies
|
|
134
|
-
command: npm ci
|
|
135
|
-
- run:
|
|
136
|
-
name: Run semantic release
|
|
137
|
-
command: npm run semantic-release
|
package/eslint.config.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import globals from 'globals'
|
|
2
|
-
import pluginJs from '@eslint/js'
|
|
3
|
-
import eslintPlugin from 'eslint-plugin-eslint-plugin'
|
|
4
|
-
import mochaPlugin from 'eslint-plugin-mocha'
|
|
5
|
-
|
|
6
|
-
export default [
|
|
7
|
-
pluginJs.configs.recommended,
|
|
8
|
-
eslintPlugin.configs['flat/recommended'],
|
|
9
|
-
mochaPlugin.configs.recommended,
|
|
10
|
-
{ignores: ['test-project/']},
|
|
11
|
-
{
|
|
12
|
-
languageOptions: {
|
|
13
|
-
globals: globals.node
|
|
14
|
-
},
|
|
15
|
-
rules: {
|
|
16
|
-
'no-redeclare': 'off',
|
|
17
|
-
'eslint-plugin/require-meta-docs-url':
|
|
18
|
-
['error', { 'pattern': 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md' }],
|
|
19
|
-
'eslint-plugin/require-meta-docs-description': 'error',
|
|
20
|
-
'eslint-plugin/meta-property-ordering': 'error',
|
|
21
|
-
'eslint-plugin/test-case-property-ordering': 'error',
|
|
22
|
-
'mocha/no-mocha-arrows': 'off',
|
|
23
|
-
'mocha/no-setup-in-describe': 'off'
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
]
|
package/jest.config.js
DELETED
package/test-project/README.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# Test-project
|
|
2
|
-
|
|
3
|
-
This test project was generated via the Cypress App.
|
|
4
|
-
|
|
5
|
-
This project can be updated to the latest Cypress default scaffolded E2E test specs by carrying out the following steps in the directory `/test-project`:
|
|
6
|
-
|
|
7
|
-
```shell
|
|
8
|
-
rm -rf cypress cypress.config.js
|
|
9
|
-
npm install cypress@latest --no-package-lock
|
|
10
|
-
npx cypress open
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
- Select "Continue" for "What's New in Cypress" if displayed
|
|
14
|
-
- Select "E2E Testing"
|
|
15
|
-
- Select "Continue" in "Configuration files"
|
|
16
|
-
- Select "Electron" browser
|
|
17
|
-
- Select "Start E2E Testing in Electron"
|
|
18
|
-
- Select "Scaffold example specs"
|
|
19
|
-
- Close all Cypress windows
|
|
20
|
-
|
|
21
|
-
Test that scaffolded specs run:
|
|
22
|
-
|
|
23
|
-
```shell
|
|
24
|
-
npm test
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Remove Cypress from `package.json`:
|
|
28
|
-
|
|
29
|
-
```shell
|
|
30
|
-
npm uninstall cypress --no-package-lock
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Tests
|
|
34
|
-
|
|
35
|
-
Tests are run via [circle.yml](../circle.yml).
|
|
36
|
-
|
|
37
|
-
To test the project locally:
|
|
38
|
-
|
|
39
|
-
```shell
|
|
40
|
-
cd test-project
|
|
41
|
-
npm install eslint@latest eslint-plugin-cypress@latest cypress@latest -D
|
|
42
|
-
npx cypress run
|
|
43
|
-
npx eslint
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Do not commit the changes from installing the above dependencies.
|
|
47
|
-
The CircleCI pipeline dynamically installs the latest `eslint*` dependencies.
|
|
48
|
-
Cypress is not needed for the CircleCI tests.
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/// <reference types="cypress" />
|
|
2
|
-
|
|
3
|
-
// Welcome to Cypress!
|
|
4
|
-
//
|
|
5
|
-
// This spec file contains a variety of sample tests
|
|
6
|
-
// for a todo list app that are designed to demonstrate
|
|
7
|
-
// the power of writing tests in Cypress.
|
|
8
|
-
//
|
|
9
|
-
// To learn more about how Cypress works and
|
|
10
|
-
// what makes it such an awesome testing tool,
|
|
11
|
-
// please read our getting started guide:
|
|
12
|
-
// https://on.cypress.io/introduction-to-cypress
|
|
13
|
-
|
|
14
|
-
describe('example to-do app', () => {
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
// Cypress starts out with a blank slate for each test
|
|
17
|
-
// so we must tell it to visit our website with the `cy.visit()` command.
|
|
18
|
-
// Since we want to visit the same URL at the start of all our tests,
|
|
19
|
-
// we include it in our beforeEach function so that it runs before each test
|
|
20
|
-
cy.visit('https://example.cypress.io/todo')
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('displays two todo items by default', () => {
|
|
24
|
-
// We use the `cy.get()` command to get all elements that match the selector.
|
|
25
|
-
// Then, we use `should` to assert that there are two matched items,
|
|
26
|
-
// which are the two default items.
|
|
27
|
-
cy.get('.todo-list li').should('have.length', 2)
|
|
28
|
-
|
|
29
|
-
// We can go even further and check that the default todos each contain
|
|
30
|
-
// the correct text. We use the `first` and `last` functions
|
|
31
|
-
// to get just the first and last matched elements individually,
|
|
32
|
-
// and then perform an assertion with `should`.
|
|
33
|
-
cy.get('.todo-list li').first().should('have.text', 'Pay electric bill')
|
|
34
|
-
cy.get('.todo-list li').last().should('have.text', 'Walk the dog')
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('can add new todo items', () => {
|
|
38
|
-
// We'll store our item text in a variable so we can reuse it
|
|
39
|
-
const newItem = 'Feed the cat'
|
|
40
|
-
|
|
41
|
-
// Let's get the input element and use the `type` command to
|
|
42
|
-
// input our new list item. After typing the content of our item,
|
|
43
|
-
// we need to type the enter key as well in order to submit the input.
|
|
44
|
-
// This input has a data-test attribute so we'll use that to select the
|
|
45
|
-
// element in accordance with best practices:
|
|
46
|
-
// https://on.cypress.io/selecting-elements
|
|
47
|
-
cy.get('[data-test=new-todo]').type(`${newItem}{enter}`)
|
|
48
|
-
|
|
49
|
-
// Now that we've typed our new item, let's check that it actually was added to the list.
|
|
50
|
-
// Since it's the newest item, it should exist as the last element in the list.
|
|
51
|
-
// In addition, with the two default items, we should have a total of 3 elements in the list.
|
|
52
|
-
// Since assertions yield the element that was asserted on,
|
|
53
|
-
// we can chain both of these assertions together into a single statement.
|
|
54
|
-
cy.get('.todo-list li')
|
|
55
|
-
.should('have.length', 3)
|
|
56
|
-
.last()
|
|
57
|
-
.should('have.text', newItem)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('can check off an item as completed', () => {
|
|
61
|
-
// In addition to using the `get` command to get an element by selector,
|
|
62
|
-
// we can also use the `contains` command to get an element by its contents.
|
|
63
|
-
// However, this will yield the <label>, which is lowest-level element that contains the text.
|
|
64
|
-
// In order to check the item, we'll find the <input> element for this <label>
|
|
65
|
-
// by traversing up the dom to the parent element. From there, we can `find`
|
|
66
|
-
// the child checkbox <input> element and use the `check` command to check it.
|
|
67
|
-
cy.contains('Pay electric bill')
|
|
68
|
-
.parent()
|
|
69
|
-
.find('input[type=checkbox]')
|
|
70
|
-
.check()
|
|
71
|
-
|
|
72
|
-
// Now that we've checked the button, we can go ahead and make sure
|
|
73
|
-
// that the list element is now marked as completed.
|
|
74
|
-
// Again we'll use `contains` to find the <label> element and then use the `parents` command
|
|
75
|
-
// to traverse multiple levels up the dom until we find the corresponding <li> element.
|
|
76
|
-
// Once we get that element, we can assert that it has the completed class.
|
|
77
|
-
cy.contains('Pay electric bill')
|
|
78
|
-
.parents('li')
|
|
79
|
-
.should('have.class', 'completed')
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
context('with a checked task', () => {
|
|
83
|
-
beforeEach(() => {
|
|
84
|
-
// We'll take the command we used above to check off an element
|
|
85
|
-
// Since we want to perform multiple tests that start with checking
|
|
86
|
-
// one element, we put it in the beforeEach hook
|
|
87
|
-
// so that it runs at the start of every test.
|
|
88
|
-
cy.contains('Pay electric bill')
|
|
89
|
-
.parent()
|
|
90
|
-
.find('input[type=checkbox]')
|
|
91
|
-
.check()
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('can filter for uncompleted tasks', () => {
|
|
95
|
-
// We'll click on the "active" button in order to
|
|
96
|
-
// display only incomplete items
|
|
97
|
-
cy.contains('Active').click()
|
|
98
|
-
|
|
99
|
-
// After filtering, we can assert that there is only the one
|
|
100
|
-
// incomplete item in the list.
|
|
101
|
-
cy.get('.todo-list li')
|
|
102
|
-
.should('have.length', 1)
|
|
103
|
-
.first()
|
|
104
|
-
.should('have.text', 'Walk the dog')
|
|
105
|
-
|
|
106
|
-
// For good measure, let's also assert that the task we checked off
|
|
107
|
-
// does not exist on the page.
|
|
108
|
-
cy.contains('Pay electric bill').should('not.exist')
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
it('can filter for completed tasks', () => {
|
|
112
|
-
// We can perform similar steps as the test above to ensure
|
|
113
|
-
// that only completed tasks are shown
|
|
114
|
-
cy.contains('Completed').click()
|
|
115
|
-
|
|
116
|
-
cy.get('.todo-list li')
|
|
117
|
-
.should('have.length', 1)
|
|
118
|
-
.first()
|
|
119
|
-
.should('have.text', 'Pay electric bill')
|
|
120
|
-
|
|
121
|
-
cy.contains('Walk the dog').should('not.exist')
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('can delete all completed tasks', () => {
|
|
125
|
-
// First, let's click the "Clear completed" button
|
|
126
|
-
// `contains` is actually serving two purposes here.
|
|
127
|
-
// First, it's ensuring that the button exists within the dom.
|
|
128
|
-
// This button only appears when at least one task is checked
|
|
129
|
-
// so this command is implicitly verifying that it does exist.
|
|
130
|
-
// Second, it selects the button so we can click it.
|
|
131
|
-
cy.contains('Clear completed').click()
|
|
132
|
-
|
|
133
|
-
// Then we can make sure that there is only one element
|
|
134
|
-
// in the list and our element does not exist
|
|
135
|
-
cy.get('.todo-list li')
|
|
136
|
-
.should('have.length', 1)
|
|
137
|
-
.should('not.have.text', 'Pay electric bill')
|
|
138
|
-
|
|
139
|
-
// Finally, make sure that the clear button no longer exists.
|
|
140
|
-
cy.contains('Clear completed').should('not.exist')
|
|
141
|
-
})
|
|
142
|
-
})
|
|
143
|
-
})
|