Skip to content

Commit 944d8d2

Browse files
authored
Bump to Cypress v12 (#135)
* upgrade Cypress to v12 * bump cypress github action versions * update a few more specs for v12 * fix a few more tests * fix more tests * remove trailing slash for JS * fix more errors * fix more errors * fix more examples * two more fixes
1 parent 7c7a642 commit 944d8d2

34 files changed

+171
-220
lines changed

.github/workflows/ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
# ~/.npm
1616
# ~/.cache/Cypress
1717
- name: Install 📦
18-
uses: cypress-io/github-action@v3
18+
uses: cypress-io/github-action@v5
1919
with:
2020
runTests: false
2121

@@ -65,7 +65,7 @@ jobs:
6565
name: built
6666

6767
- name: Install 📦
68-
uses: cypress-io/github-action@v3
68+
uses: cypress-io/github-action@v5
6969
with:
7070
runTests: false
7171

@@ -97,7 +97,7 @@ jobs:
9797
# download cached ~/.npm and ~/.cache/Cypress
9898
# and install node_modules
9999
- name: Cypress tests 🧪
100-
uses: cypress-io/github-action@v3
100+
uses: cypress-io/github-action@v5
101101
# run all tests straight from Markdown files
102102
# using Cypress GH action
103103
# https://github.com/cypress-io/github-action
@@ -147,7 +147,7 @@ jobs:
147147
name: built
148148

149149
- name: Test built site 🧪
150-
uses: cypress-io/github-action@v3
150+
uses: cypress-io/github-action@v5
151151
with:
152152
start: npm run serve
153153
config-file: cypress-dist.json
@@ -179,7 +179,7 @@ jobs:
179179
name: built
180180

181181
- name: Install 📦
182-
uses: cypress-io/github-action@v3
182+
uses: cypress-io/github-action@v5
183183
with:
184184
runTests: false
185185

.github/workflows/deployed.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
persist-credentials: false
2828

2929
- name: Install dependencies 📦
30-
uses: cypress-io/github-action@v3
30+
uses: cypress-io/github-action@v5
3131
with:
3232
# just perform install
3333
runTests: false
@@ -56,7 +56,7 @@ jobs:
5656
run: cat docs/**/*.js > docs/run-all-specs.js
5757

5858
- name: Test deployed site 🧪💨
59-
uses: cypress-io/github-action@v3
59+
uses: cypress-io/github-action@v5
6060
with:
6161
# we have already installed all dependencies above
6262
install: false

.github/workflows/scrape.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
persist-credentials: false
2020

2121
- name: Install dependencies 📦
22-
uses: cypress-io/github-action@v3
22+
uses: cypress-io/github-action@v5
2323
with:
2424
# just perform install
2525
runTests: false

cypress.config.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const { defineConfig } = require('cypress')
2+
3+
module.exports = defineConfig({
4+
fixturesFolder: 'cypress/fixtures',
5+
viewportHeight: 1000,
6+
viewportWidth: 600,
7+
env: {
8+
'cypress-fiddle': {
9+
stylesheets: [
10+
'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css',
11+
],
12+
style:
13+
'body { padding: 2rem; } .action-focus.focus { border: 5px solid orange; } .hidden { display: none !important; }',
14+
},
15+
'cypress-book': {
16+
imageFolder: './pics',
17+
tolerance: 0.02,
18+
},
19+
},
20+
projectId: 'dis6wg',
21+
video: false,
22+
e2e: {
23+
// We've imported your old cypress plugins here.
24+
// You may want to clean this up later by importing these.
25+
setupNodeEvents(on, config) {
26+
return require('./plugins.js')(on, config)
27+
},
28+
specPattern: 'docs/**/*.md',
29+
},
30+
})

cypress.json

-23
This file was deleted.

cypress/fixtures/example.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "Using fixtures to represent data",
33
"email": "[email protected]",
4-
"body": "Fixtures are a great way to mock data for responses to routes"
4+
"text": "Fixtures are a great way to mock data for responses to routes"
55
}
File renamed without changes.

docs/commands/aliasing.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,16 @@ cy.get('[data-cy=query-the-alias]').within(() => {
140140

141141
```js
142142
// Alias the route to wait for its response
143-
cy.server()
144-
cy.route('GET', 'comments/*').as('getComment')
143+
cy.intercept('GET', 'comments/*').as('getComment')
145144

146145
// we have code that gets a comment when
147146
// the button is clicked in scripts.js
148147
cy.get('.network-btn').click()
149148

150149
// https://on.cypress.io/wait
151-
cy.wait('@getComment').its('status').should('eq', 200)
150+
cy.wait('@getComment')
151+
.its('response.statusCode')
152+
.should('eq', 200)
152153
```
153154

154155
<!-- fiddle-end -->

docs/commands/assertions.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1870,15 +1870,14 @@ This is especially useful when dealing with dimensions of elements on the page,
18701870

18711871
```html
18721872
<div id="font-size-example">This is my message</div>
1873-
<style></style>
18741873
```
18751874

18761875
```js
18771876
cy.get('#font-size-example')
18781877
.invoke('css', 'fontSize')
1879-
.then(cy.log)
1878+
.should('be.a', 'string')
18801879
// the font size returned is in pixels, like "16px"
1881-
.should('match', /^\d+px$/)
1880+
.and('match', /^\d+px$/)
18821881
.invoke('replace', 'px', '')
18831882
.then(Number)
18841883
.should('be.closeTo', 16, 1)

docs/commands/files.md

+16-25
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,26 @@ To load a fixture, use the `cy.fixture()` command.
3232
```js
3333
// Instead of writing a response inline you can
3434
// use a fixture file's content.
35+
cy.fixture('example.json').then((comment) => {
36+
cy.intercept('GET', 'comments/*', comment).as('getComment')
37+
})
38+
```
3539

36-
cy.server()
37-
cy.fixture('example.json').as('comment')
38-
cy.route('GET', 'comments/*', '@comment').as('getComment')
40+
We have code that gets a comment when the button is clicked in `scripts.js`
3941

40-
// we have code that gets a comment when
41-
// the button is clicked in scripts.js
42+
```js
4243
cy.get('.fixture-btn').click()
4344

4445
cy.wait('@getComment')
45-
.its('responseBody')
46+
.its('response.body')
4647
.should('have.property', 'name')
4748
.and('include', 'Using fixtures to represent data')
49+
```
50+
51+
You can also just write the fixture in the route
4852

49-
// you can also just write the fixture in the route
50-
cy.route('GET', 'comments', 'fixture:example.json').as(
53+
```js
54+
cy.intercept('GET', 'comments', { fixture: 'example.json' }).as(
5155
'getComment',
5256
)
5357

@@ -56,20 +60,7 @@ cy.route('GET', 'comments', 'fixture:example.json').as(
5660
cy.get('.fixture-btn').click()
5761

5862
cy.wait('@getComment')
59-
.its('responseBody')
60-
.should('have.property', 'name')
61-
.and('include', 'Using fixtures to represent data')
62-
63-
// or write fx to represent fixture
64-
// by default it assumes it's .json
65-
cy.route('GET', 'comments', 'fx:example').as('getComment')
66-
67-
// we have code that gets a comment when
68-
// the button is clicked in scripts.js
69-
cy.get('.fixture-btn').click()
70-
71-
cy.wait('@getComment')
72-
.its('responseBody')
63+
.its('response.body')
7364
.should('have.property', 'name')
7465
.and('include', 'Using fixtures to represent data')
7566
```
@@ -107,23 +98,23 @@ To read a file's content, use the `cy.readFile()` command.
10798
```js
10899
// You can read a file and yield its contents
109100
// The filePath is relative to your project's root.
110-
cy.readFile('cypress.json').then((json) => {
101+
cy.readFile('cypress/fixtures/example.json').then((json) => {
111102
expect(json, 'parsed json').to.be.an('object')
112103
})
113104
```
114105

115106
JSON files are automatically parsed, so if you want the raw text, you need to convert it back. For example, you can go through a `Cypress.Buffer`
116107

117108
```js
118-
cy.readFile('cypress.json', null)
109+
cy.readFile('cypress/fixtures/example.json', null)
119110
.invoke('toString')
120111
.should('be.a', 'string')
121112
```
122113

123114
Or by convert the object to a JSON string
124115

125116
```js
126-
cy.readFile('cypress.json')
117+
cy.readFile('cypress/fixtures/example.json')
127118
.then(JSON.stringify)
128119
.should('be.a', 'string')
129120
```

docs/commands/misc.md

+21-11
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,17 @@ Let's say we want to print to the Command Log the number of elements the previou
4242
cy.get('#log-fruits li')
4343
// you can add assertions to make sure the list is populated
4444
.its('length')
45-
// prints just the number
46-
.then(cy.log)
45+
// prints just the number,
46+
// must be careful to yield the value to the next command
47+
.then((x) => {
48+
cy.log(x)
49+
cy.wrap(x, { log: false })
50+
})
4751
// if you want to add a message, use a callback function
48-
.then((n) => cy.log(`found ${n} items`))
52+
.then((n) => {
53+
cy.log(`found ${n} items`)
54+
cy.wrap(n, { log: false })
55+
})
4956
// because cy.log never changes the current subject
5057
// we can confirm the found number of elements by adding an assertion
5158
.should('equal', 5)
@@ -59,18 +66,21 @@ cy.get('#log-fruits li')
5966
.filter(':contains("Grape")')
6067
.its('length')
6168
// if you want to add a message, use a callback function
62-
.then((n) => cy.log(`found ${n} fruits with "Grape" in them`))
69+
.then((n) => {
70+
cy.log(`found ${n} fruits with "Grape" in them`)
71+
cy.wrap(n, { log: false })
72+
})
6373
// confirm the number of elements
6474
.should('equal', 2)
6575
```
6676

6777
<!-- fiddle-end -->
6878

69-
### cy.log yields the original argument
79+
### cy.log does not yield the original argument
7080

71-
Because `cy.log` yields `undefined`, Cypress will yield the original argument to the next command or assertion. For example, let's print the element's node name and then confirm its value.
81+
Because `cy.log` yields `null`, Cypress will NOT yield the original argument to the next command or assertion. Thus you need to wrap the original value.
7282

73-
<!-- fiddle .log() / yields the original argument -->
83+
<!-- fiddle .log() / does not yield the original argument -->
7484

7585
```html
7686
<button name="log-me">Submit</button>
@@ -82,9 +92,9 @@ cy.get('[name=log-me]')
8292
// of that HTML prop
8393
.should('have.prop', 'nodeName')
8494
// prints the nodeName value to the Command Log
85-
// and yields it to the next step
95+
// and yields NULL to the next step
8696
.then(cy.log)
87-
.should('equal', 'BUTTON')
97+
.should('equal', null)
8898
```
8999

90100
<!-- fiddle-end -->
@@ -227,9 +237,9 @@ cy.exec('echo Jane Lane')
227237
.should('contain', 'Jane Lane')
228238

229239
if (Cypress.platform === 'win32') {
230-
cy.exec('print cypress.json').its('stderr').should('be.empty')
240+
cy.exec('print renovate.json').its('stderr').should('be.empty')
231241
} else {
232-
cy.exec('cat cypress.json').its('stderr').should('be.empty')
242+
cy.exec('cat renovate.json').its('stderr').should('be.empty')
233243

234244
cy.exec('pwd').its('code').should('eq', 0)
235245
}

docs/commands/network-requests.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ _Deprecated_ in Cypress v6
88

99
To control the behavior of network requests and responses, use the `cy.server()` command.
1010

11-
<!-- fiddle cy.server() - control behavior of network requests and responses -->
11+
<!-- fiddle.skip cy.server() - control behavior of network requests and responses -->
1212

1313
```js
1414
// https://on.cypress.io/server
@@ -245,7 +245,7 @@ _Deprecated_ in Cypress v6
245245

246246
To route responses to matching requests, use the `cy.route()` command.
247247

248-
<!-- fiddle cy.route() - route responses to matching requests -->
248+
<!-- fiddle.skip cy.route() - route responses to matching requests -->
249249
<!-- fiddle-markup
250250
<style>
251251
.network-route-btn,

docs/commands/querying.md

+12-20
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,9 @@ In the HTML below all links have the class "help", but some links have the class
317317
```js
318318
cy.get('a.help:not(.external)')
319319
.should('have.length', 2)
320-
.within(() => {
321-
// confirm the two found elements
322-
cy.root().eq(0).should('have.text', 'Article 2')
323-
cy.root().eq(1).should('have.text', 'index')
324-
})
320+
// confirm the two found elements
321+
.then(($el) => Cypress._.map($el, 'innerText'))
322+
.should('deep.equal', ['Article 2', 'index'])
325323
```
326324

327325
<!-- fiddle-end -->
@@ -1394,9 +1392,9 @@ cy.get('picture').within(() => {
13941392

13951393
### Within works with multiple elements
13961394

1397-
The parent command can yield multiple elements.
1395+
The command `cy.within` requires the parent subject to be a single element.
13981396

1399-
<!-- fiddle .within / multiple elements -->
1397+
<!-- fiddle.skip .within / multiple elements -->
14001398

14011399
```html
14021400
<ul id="fruits">
@@ -1406,19 +1404,13 @@ The parent command can yield multiple elements.
14061404
```
14071405

14081406
```js
1409-
cy.get('#fruits li').within(() => {
1410-
cy.root().should('have.length', 2) // there are 2 LI items
1411-
cy.contains('a', 'Apples').should(
1412-
'have.attr',
1413-
'href',
1414-
'/apples',
1415-
)
1416-
cy.contains('a', 'Oranges').should(
1417-
'have.attr',
1418-
'href',
1419-
'/oranges',
1420-
)
1421-
})
1407+
cy.get('#fruits li')
1408+
.should('have.length', 2) // there are 2 LI items
1409+
// 🚨 NOT GOING TO WORK
1410+
// "Your subject contained 2 elements"
1411+
.within(() => {
1412+
// Nope, not going to get here
1413+
})
14221414
```
14231415

14241416
<!-- fiddle-end -->

0 commit comments

Comments
 (0)