Skip to content

Commit fba292f

Browse files
flotwigbahmutov
andauthored
feat: kitchensink for Cypress v6.0.0 Release (#452)
Co-authored-by: Gleb Bahmutov <[email protected]>
1 parent cb5e95d commit fba292f

File tree

13 files changed

+68
-221
lines changed

13 files changed

+68
-221
lines changed

.circleci/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ workflows:
108108
- run: npx cypress cache path
109109
- run: npx cypress cache list
110110
- run: npx cypress info
111+
# let's print version info
112+
- run: npx cypress version
113+
- run: npx cypress version --component package
114+
- run: npx cypress version --component binary
115+
- run: npx cypress version --component electron
116+
- run: npx cypress version --component node
111117

112118
# runs on 3 machines, load balances tests
113119
# and records on Cypress Dashboard

.github/workflows/single.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ jobs:
4848
env:
4949
# make sure every Cypress install prints minimal information
5050
CI: 1
51+
# print Cypress and OS info
5152
run: |
5253
npm ci
5354
npx cypress verify
5455
npx cypress info
56+
npx cypress version
57+
npx cypress version --component package
58+
npx cypress version --component binary
59+
npx cypress version --component electron
60+
npx cypress version --component node
5561
5662
# Starts local server, then runs Cypress tests and records results on the dashboard
5763
- name: Cypress tests

app/assets/js/scripts.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ $(() => {
134134
url: `${root}/comments`,
135135
method: 'POST',
136136
data: {
137-
name: 'Using POST in cy.route()',
137+
name: 'Using POST in cy.intercept()',
138138
139-
body: 'You can change the method used for cy.route() to be GET, POST, PUT, PATCH, or DELETE',
139+
body: 'You can change the method used for cy.intercept() to be GET, POST, PUT, PATCH, or DELETE',
140140
},
141141
}).then(() => {
142142
$('.network-post-comment').text('POST successful!')
@@ -148,9 +148,9 @@ $(() => {
148148
url: `${root}/comments/1`,
149149
method: 'PUT',
150150
data: {
151-
name: 'Using PUT in cy.route()',
151+
name: 'Using PUT in cy.intercept()',
152152
153-
body: 'You can change the method used for cy.route() to be GET, POST, PUT, PATCH, or DELETE',
153+
body: 'You can change the method used for cy.intercept() to be GET, POST, PUT, PATCH, or DELETE',
154154
},
155155
statusCode: {
156156
404 (data) {

app/commands/aliasing.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ <h1>Aliasing</h1>
7474
<div class="col-xs-7">
7575
<h4><a href="https://on.cypress.io/as">.as()</a></h4>
7676
<p>To alias a route or DOM element for use later, use the <a href="https://on.cypress.io/api/as"><code>.as()</code></a> command.</p>
77-
<pre><code class="javascript">
77+
<pre><code class="javascript">
7878
// The following DOM command chain is unwieldy.
7979
// To avoid repeating it, let's use `.as()`!
8080
cy.get('.as-table')
@@ -92,15 +92,14 @@ <h4><a href="https://on.cypress.io/as">.as()</a></h4>
9292

9393
// Alias the route to wait for its response
9494

95-
cy.server()
96-
cy.route('GET', 'comments/*').as('getComment')
95+
cy.intercept('GET', '**/comments/*').as('getComment')
9796

9897
// we have code that gets a comment when
9998
// the button is clicked in scripts.js
10099
cy.get('.network-btn').click()
101100

102101
// https://on.cypress.io/wait
103-
cy.wait('@getComment').its('status').should('eq', 200)
102+
cy.wait('@getComment').its('response.statusCode').should('eq', 200)
104103
</code></pre>
105104
</div>
106105
<div class="col-xs-5">

app/commands/files.html

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,38 +77,15 @@ <h4 id="fixture"><a href="https://on.cypress.io/fixture">cy.fixture()</a></h4>
7777
<pre><code class="javascript">// Instead of writing a response inline you can
7878
// use a fixture file's content.
7979

80-
cy.server()
81-
cy.fixture('example.json').as('comment')
82-
cy.route('GET', 'comments', '@comment').as('getComment')
80+
// when application makes an Ajax request matching "GET **/comments/*"
81+
// Cypress will intercept it and reply with the object in `example.json` fixture
82+
cy.intercept('GET', '**/comments/*', { fixture: 'example.json' }).as('getComment')
8383

8484
// we have code that gets a comment when
8585
// the button is clicked in scripts.js
8686
cy.get('.fixture-btn').click()
8787

88-
cy.wait('@getComment').its('responseBody')
89-
.should('have.property', 'name')
90-
.and('include', 'Using fixtures to represent data')
91-
92-
// you can also just write the fixture in the route
93-
cy.route('GET', 'comments', 'fixture:example.json').as('getComment')
94-
95-
// we have code that gets a comment when
96-
// the button is clicked in scripts.js
97-
cy.get('.fixture-btn').click()
98-
99-
cy.wait('@getComment').its('responseBody')
100-
.should('have.property', 'name')
101-
.and('include', 'Using fixtures to represent data')
102-
103-
// or write fx to represent fixture
104-
// by default it assumes it's .json
105-
cy.route('GET', 'comments', 'fx:example').as('getComment')
106-
107-
// we have code that gets a comment when
108-
// the button is clicked in scripts.js
109-
cy.get('.fixture-btn').click()
110-
111-
cy.wait('@getComment').its('responseBody')
88+
cy.wait('@getComment').its('response.body')
11289
.should('have.property', 'name')
11390
.and('include', 'Using fixtures to represent data')</code></pre>
11491
</div>

app/commands/network-requests.html

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -63,52 +63,13 @@
6363
<div class="banner">
6464
<div class="container">
6565
<h1>Network Requests</h1>
66-
<p>Examples of handling AJAX or XHR requests in Cypress, for a full reference of commands, go to <a href="https://on.cypress.io/api" target="_blank">docs.cypress.io</a>
66+
<p>Examples of handling HTTP requests in Cypress, for a full reference of commands, go to <a href="https://on.cypress.io/api" target="_blank">docs.cypress.io</a>
6767
</p>
6868
</div>
6969
</div>
7070
<div class="container content-container">
7171
<div id="network-requests">
7272
<div class="row">
73-
74-
<div class="col-xs-7">
75-
<h4 id="server"><a href="https://on.cypress.io/server">cy.server()</a></h4>
76-
<p>To control the behavior of network requests and responses, use the <a href="https://on.cypress.io/server"><code>cy.server()</code></a> command.</p>
77-
<pre><code class="javascript">cy.server().should((server) => {
78-
// the default options on server
79-
// you can override any of these options
80-
expect(server.delay).to.eq(0)
81-
expect(server.method).to.eq('GET')
82-
expect(server.status).to.eq(200)
83-
expect(server.headers).to.be.null
84-
expect(server.response).to.be.null
85-
expect(server.onRequest).to.be.undefined
86-
expect(server.onResponse).to.be.undefined
87-
expect(server.onAbort).to.be.undefined
88-
89-
// These options control the server behavior
90-
// affecting all requests
91-
92-
// pass false to disable existing route stubs
93-
expect(server.enable).to.be.true
94-
// forces requests that don't match your routes to 404
95-
expect(server.force404).to.be.false
96-
// ignores requests from ever being logged or stubbed
97-
expect(server.ignore).to.be.a('function')
98-
})
99-
100-
cy.server({
101-
method: 'POST',
102-
delay: 1000,
103-
status: 422,
104-
response: {},
105-
})</code></pre>
106-
</div>
107-
<div class="col-xs-5">
108-
</div>
109-
110-
<div class="col-xs-12"><hr></div>
111-
11273
<div class="col-xs-7">
11374
<h4 id="request"><a href="https://on.cypress.io/request">cy.request()</a></h4>
11475
<p>To make an XHR request, use the <a href="https://on.cypress.io/request"><code>cy.request()</code></a> command.</p>
@@ -181,43 +142,41 @@ <h4 id="request"><a href="https://on.cypress.io/request">cy.request()</a></h4>
181142
<div class="col-xs-12"><hr></div>
182143

183144
<div class="col-xs-7">
184-
<h4 id="route"><a href="https://on.cypress.io/route">cy.route()</a></h4>
185-
<p>To route responses to matching requests, use the <a href="https://on.cypress.io/route"><code>cy.route()</code></a> command.</p>
186-
<pre><code class="javascript">let message = 'whoa, this comment does not exist'
187-
cy.server()
145+
<h4 id="http"><a href="https://on.cypress.io/http">cy.intercept()</a></h4>
146+
<p>To route responses to matching requests, use the <a href="https://on.cypress.io/http"><code>cy.intercept()</code></a> command.</p>
147+
<pre><code class="javascript"> let message = 'whoa, this comment does not exist'
188148

189149
// Listen to GET to comments/1
190-
cy.route('GET', 'comments/*').as('getComment')
150+
cy.intercept('GET', '**/comments/*').as('getComment')
191151

192152
// we have code that gets a comment when
193153
// the button is clicked in scripts.js
194154
cy.get('.network-btn').click()
195155

196156
// https://on.cypress.io/wait
197-
cy.wait('@getComment').its('status').should('eq', 200)
157+
cy.wait('@getComment').its('response.statusCode').should('be.oneOf', [200, 304])
198158

199159
// Listen to POST to comments
200-
cy.route('POST', '/comments').as('postComment')
160+
cy.intercept('POST', '**/comments').as('postComment')
201161

202162
// we have code that posts a comment when
203163
// the button is clicked in scripts.js
204164
cy.get('.network-post').click()
205-
cy.wait('@postComment')
206-
207-
// get the route
208-
cy.get('@postComment').should((xhr) => {
209-
expect(xhr.requestBody).to.include('email')
210-
expect(xhr.requestHeaders).to.have.property('Content-Type')
211-
expect(xhr.responseBody).to.have.property('name', 'Using POST in cy.route()')
165+
cy.wait('@postComment').should(({ request, response }) => {
166+
expect(request.body).to.include('email')
167+
expect(request.headers).to.have.property('content-type')
168+
expect(response && response.body).to.have.property('name', 'Using POST in cy.intercept()')
212169
})
213170

214171
// Stub a response to PUT comments/ ****
215-
cy.route({
172+
cy.intercept({
216173
method: 'PUT',
217-
url: 'comments/*',
218-
status: 404,
219-
response: { error: message },
220-
delay: 500,
174+
url: '**/comments/*',
175+
}, {
176+
statusCode: 404,
177+
body: { error: message },
178+
headers: { 'access-control-allow-origin': '*' },
179+
delayMs: 500,
221180
}).as('putComment')
222181

223182
// we have code that puts a comment when

app/commands/waiting.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,15 @@ <h4><a href="https://on.cypress.io/wait">cy.wait()</a></h4>
8080
cy.get('.wait-input3').type('Wait 1000ms after typing')
8181
cy.wait(1000)
8282

83-
cy.server()
84-
8583
// Listen to GET to comments/1
86-
cy.route('GET', 'comments/*').as('getComment')
84+
cy.intercept('GET', '**/comments/*').as('getComment')
8785

8886
// we have code that gets a comment when
8987
// the button is clicked in scripts.js
9088
cy.get('.network-btn').click()
9189

9290
// wait for GET comments/1
93-
cy.wait('@getComment').its('status').should('eq', 200)</code></pre>
91+
cy.wait('@getComment').its('response.statusCode').should('be.oneOf', [200, 304])</code></pre>
9492
</div>
9593
<div class="col-xs-5">
9694
<div class="well">

app/cypress-api.html

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,6 @@ <h4 id="Cookies.default"><a href="https://on.cypress.io/cookies">Cypress.Cookies
126126

127127
<div class="col-xs-12"><hr></div>
128128

129-
<div class="col-xs-12">
130-
<h4 id="Server.default"><a href="https://on.cypress.io/cypress-server">Cypress.Server.default()</a></h4>
131-
<p>To change the default configuration for <code>cy.server</code>, use <a href="https://on.cypress.io/cypress-server"><code>Cypress.Server.defaults()</code></a>.</p>
132-
<pre><code class="javascript">Cypress.Server.defaults({
133-
delay: 0,
134-
force404: true,
135-
ignore: function(xhr){
136-
// handle custom logic for ignoring XHRs
137-
}
138-
})</code></pre>
139-
</div>
140-
141-
<div class="col-xs-12"><hr></div>
142-
143129
<div class="col-xs-12">
144130
<h4 id="arch"><a href="https://on.cypress.io/arch">Cypress.arch</a></h4>
145131
<p>To get CPU architecture name of underlying OS, use <a href="https://on.cypress.io/arch"><code>Cypress.arch</code></a>.</p>

cypress/integration/examples/aliasing.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ context('Aliasing', () => {
2727

2828
it('.as() - alias a route for later use', () => {
2929
// Alias the route to wait for its response
30-
cy.server()
31-
cy.route('GET', 'comments/*').as('getComment')
30+
cy.intercept('GET', '**/comments/*').as('getComment')
3231

3332
// we have code that gets a comment when
3433
// the button is clicked in scripts.js
3534
cy.get('.network-btn').click()
3635

3736
// https://on.cypress.io/wait
38-
cy.wait('@getComment').its('status').should('eq', 200)
37+
cy.wait('@getComment').its('response.statusCode').should('eq', 200)
3938
})
4039
})

cypress/integration/examples/cypress_api.spec.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,6 @@ context('Cypress.Cookies', () => {
7373
})
7474
})
7575

76-
context('Cypress.Server', () => {
77-
beforeEach(() => {
78-
cy.visit('http://localhost:8080/cypress-api')
79-
})
80-
81-
// Permanently override server options for
82-
// all instances of cy.server()
83-
84-
// https://on.cypress.io/cypress-server
85-
it('.defaults() - change default config of server', () => {
86-
Cypress.Server.defaults({
87-
delay: 0,
88-
force404: false,
89-
})
90-
})
91-
})
92-
9376
context('Cypress.arch', () => {
9477
beforeEach(() => {
9578
cy.visit('http://localhost:8080/cypress-api')

0 commit comments

Comments
 (0)