Skip to content

Commit c1d0cf9

Browse files
authored
Merge pull request #61 from Lakitna/attribute-command-retry-fix
Attribute command retry fix
2 parents 40cc002 + c8690a4 commit c1d0cf9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+8552
-4184
lines changed

.editorconfig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Editor configuration, see https://editorconfig.org
2+
# Used by various tools. Among which: VS Code, Prettier
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 4
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
end_of_line = lf
12+
13+
[*.ts]
14+
quote_type = single
15+
16+
[*.js]
17+
quote_type = single
18+
19+
[*.md]
20+
trim_trailing_whitespace = false
21+
indent_style = space
22+
indent_size = 2
23+
24+
[*.yaml]
25+
indent_style = space
26+
indent_size = 2
27+
28+
[{package.json,package-lock.json}]
29+
indent_style = space
30+
indent_size = 2

.eslintrc.js

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,55 @@
1+
/* eslint-disable sonarjs/no-duplicate-string */
12
module.exports = {
2-
"plugins": [
3-
"sonarjs",
4-
"cypress",
5-
],
6-
"extends": [
7-
"google",
8-
"plugin:sonarjs/recommended",
9-
"plugin:cypress/recommended",
10-
],
11-
"parserOptions": {
12-
"sourceType": "module",
13-
"ecmaVersion": 8
3+
plugins: ['sonarjs', 'cypress'],
4+
extends: ['google', 'plugin:sonarjs/recommended', 'plugin:cypress/recommended'],
5+
parserOptions: {
6+
sourceType: 'module',
7+
ecmaVersion: 8,
148
},
15-
"env": {
16-
"node": true,
17-
"es6": true,
9+
env: {
10+
node: true,
11+
es6: true,
1812
},
19-
"rules": {
20-
"indent": [
21-
"error",
22-
4,
23-
],
24-
"max-len": [
25-
"error",
26-
100,
13+
rules: {
14+
'indent': ['error', 4],
15+
'max-len': ['error', 100],
16+
'linebreak-style': 'off',
17+
'no-multi-spaces': [
18+
'error',
19+
{
20+
exceptions: {
21+
VariableDeclarator: true,
22+
},
23+
},
2724
],
28-
"linebreak-style": "off",
29-
"no-multi-spaces": [
30-
"error", {
31-
"exceptions": {
32-
"VariableDeclarator": true,
33-
}
34-
}
25+
'object-curly-spacing': ['error', 'always'],
26+
'comma-dangle': [
27+
'error',
28+
{
29+
arrays: 'always-multiline',
30+
objects: 'always-multiline',
31+
imports: 'always-multiline',
32+
exports: 'always-multiline',
33+
functions: 'never',
34+
},
3535
],
36-
"brace-style": [
37-
"error",
38-
"stroustrup",
36+
'space-before-function-paren': [
37+
'error',
38+
{
39+
anonymous: 'always',
40+
named: 'never',
41+
asyncArrow: 'always',
42+
},
3943
],
40-
"object-curly-spacing": ["error", "always"],
41-
"operator-linebreak": ["error", "before"],
4244
},
43-
"overrides": [{
44-
"files": ["lib/**/*"],
45-
"rules": {
46-
// This is fine as long as you know what you're doing
47-
"cypress/no-assigning-return-values": "warn",
48-
}
49-
},
50-
{
51-
"files": ["cypress/integration/**/*"],
52-
"rules": {
53-
"sonarjs/no-identical-functions": "warn",
54-
"sonarjs/no-duplicate-string": ["warn", 5],
55-
"no-invalid-this": "off",
45+
overrides: [
46+
{
47+
files: ['cypress/integration/**/*'],
48+
rules: {
49+
'sonarjs/no-identical-functions': 'warn',
50+
'sonarjs/no-duplicate-string': ['warn', 5],
51+
'no-invalid-this': 'off',
52+
},
5653
},
57-
}],
54+
],
5855
};

.github/workflows/ci.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [develop]
9+
pull_request:
10+
branches: [develop]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
20+
node-version: [10.x, 14.x, 16.x]
21+
22+
# Runs with `package.json` use the version defined in `~/package.lock.json`.
23+
cypress-version: [package.json, 8.2, 6]
24+
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Use Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v2
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
cache: 'npm'
32+
- run: npm ci
33+
- if: ${{ matrix.cypress-version != 'package.json' }}
34+
run: npm install cypress@${{ matrix.cypress-version }}
35+
- run: npm run lint
36+
- run: npm run test:source
37+
- run: npm run bundle
38+
- run: npm run test:bundle

.jsbeautifyrc

Lines changed: 0 additions & 26 deletions
This file was deleted.

.prettierrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"singleQuote": true,
3+
"semi": true,
4+
"bracketSpacing": true,
5+
"trailingComma": "es5",
6+
"proseWrap": "always",
7+
"printWidth": 100,
8+
"quoteProps": "consistent"
9+
}

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.vscode/extentions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["esbenp.prettier-vscode"]
3+
}

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode"
4+
}

CHANGELOG.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## 2.0.0 - 2021-09-13
6+
7+
### Breaking changes
8+
9+
#### Whitespace handling for zero-width whitespace in `.text()` and `.attribute()`
10+
11+
Whitespace handling in `.text()` and `.attribute()` has been changed to no longer consider
12+
zero-width whitespace to be whitespace in modes `{whitespace: 'simplify'}` and
13+
`{whitespace: 'keep-newline'}`. Mode `{whitespace: 'keep'}` has not changed.
14+
15+
<!-- prettier-ignore -->
16+
```html
17+
<div>super\u200Bcalifragilistic\u200Bexpialidocious</div>
18+
```
19+
20+
```javascript
21+
// Old situation
22+
cy.get('div').text().should('equal', 'super califragilistic expialidocious');
23+
```
24+
25+
```javascript
26+
// New situation
27+
cy.get('div').text().should('equal', 'supercalifragilisticexpialidocious');
28+
```
29+
30+
When using `.text()` on elements containing the `<wbr>` tag: `<wbr>` is now considered a zero-width
31+
space and will thus be removed with whitespace `simplify` and `keep-newline` as described above.
32+
33+
<!-- prettier-ignore -->
34+
```html
35+
<div>super<wbr>califragilistic<wbr>expialidocious</div>
36+
```
37+
38+
```javascript
39+
// Old situation
40+
cy.get('div').text().should('equal', 'super califragilistic expialidocious');
41+
```
42+
43+
```javascript
44+
// New situation
45+
cy.get('div').text().should('equal', 'supercalifragilisticexpialidocious');
46+
```
47+
48+
#### Output order of `.text()`
49+
50+
When using `.text({ depth: Number })` the order of texts has been changed to better reflect what the
51+
user sees. It will now first traverse all the way to the deepest point, before going sideways. This
52+
will make `.text()` behave much better with inline styling and links.
53+
54+
<!-- prettier-ignore -->
55+
```html
56+
<div class="parent">
57+
parent div top
58+
<div>
59+
child div
60+
</div>
61+
parent div middle
62+
<div>
63+
second-child div
64+
</div>
65+
parent div bottom
66+
</div>
67+
```
68+
69+
```javascript
70+
// Old situation
71+
// Note how the first part of the string is the various parts of `div.parent`
72+
cy.get('parent')
73+
.text({ depth: 1 })
74+
.should('equal', 'parent div top parent div middle parent div bottom child div second-child div');
75+
```
76+
77+
```javascript
78+
// New situation
79+
cy.get('div')
80+
.text({ depth: 1 })
81+
.should('equal', 'parent div top child div parent div middle second-child div parent div bottom');
82+
```
83+
84+
Inline text formatting:
85+
86+
<!-- prettier-ignore -->
87+
```html
88+
<div>
89+
Text with <b>some</b> styling and <a href="...">a link</a>.
90+
</div>
91+
```
92+
93+
```javascript
94+
// Old situation
95+
cy.get('div').text({ depth: 1 }).should('equal', 'Text with styling and . some a link');
96+
```
97+
98+
```javascript
99+
// New situation
100+
cy.get('div').text({ depth: 1 }).should('equal', 'Text with some styling and a link.');
101+
```
102+
103+
#### Stricter types
104+
105+
Types have been made stricter for `.attribute()`, `text()`, and `.to()`. This is a great improvement
106+
for TypeScript users as it reduces any manual casting. It allows for things like:
107+
108+
```typescript
109+
cy.get('div')
110+
.text() // yields type 'string | string[]'
111+
.to('array') // yields type 'string[]'
112+
.then((texts: string[]) => ...);
113+
```
114+
115+
```typescript
116+
cy.get('div')
117+
.attribute('class') // yields type 'string | string[]'
118+
.to('array') // yields type 'string[]'
119+
.then((texts: string[]) => ...);
120+
```
121+
122+
### Fixes
123+
124+
- Support for Cypress 8.3.0 and above. There was a change in an internal API used for the
125+
`.attribute()` command. This internal API allows us to do some complex stuff with
126+
`{strict: true}`. The fix does not impact versions <= 8.2.0. See #60 for details.
127+
128+
- `.attribute()` would not work properly in situations where it finds one attribute with a string
129+
length longer than the number of elements. For example:
130+
131+
<!-- prettier-ignore -->
132+
```html
133+
<div data-foo="hello"></div>
134+
<div></div>
135+
<div></div>
136+
```
137+
138+
```javascript
139+
cy.get('div').attribute('data-foo'); // Throws error because `hello`.length > $elements.length
140+
```
141+
142+
This change also prompted some refactoring.
143+
144+
- Updated docs based on changed made upstream in the Cypress docs.
145+
146+
- Added config for Prettier/editorconfig and Eslint rules to match them. Reformatted a lot of files
147+
because of this.
148+
149+
- Moved CI from Travis to Github. Now tests on multiple versions of NodeJS and multiple versions of
150+
Cypress.
151+
152+
- Updated a lot of dependencies. It was over due.
153+
154+
- Switched use of `path` to `path-browserify` to reduce config overhead for TypeScript users.

0 commit comments

Comments
 (0)