Skip to content

Commit f2bee8a

Browse files
committed
fix: removing cy.server and cy.route
1 parent 73504f1 commit f2bee8a

File tree

23 files changed

+45281
-256
lines changed

23 files changed

+45281
-256
lines changed

examples/blogs__e2e-snapshots/cypress/e2e/api-spec.cy.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ describe('via API', () => {
5353

5454
describe('initial', () => {
5555
it('todos', () => {
56-
cy.server()
57-
cy.route('/todos', [
56+
cy.intercept('/todos', [
5857
{
5958
title: 'mock first',
6059
completed: false,
@@ -123,11 +122,7 @@ describe('API', () => {
123122
})
124123

125124
it('is adding todo item', () => {
126-
cy.server()
127-
cy.route({
128-
method: 'POST',
129-
url: '/todos',
130-
}).as('postTodo')
125+
cy.intercept('POST', '/todos').as('postTodo')
131126

132127
// go through the UI
133128
enterTodo('first item') // id "1"
@@ -140,11 +135,7 @@ describe('API', () => {
140135
})
141136

142137
it('is deleting a todo item', () => {
143-
cy.server()
144-
cy.route({
145-
method: 'DELETE',
146-
url: '/todos/1',
147-
}).as('deleteTodo')
138+
cy.intercept('DELETE', '/todos/1').as('deleteTodo')
148139

149140
// go through the UI
150141
enterTodo('first item') // id "1"

examples/blogs__e2e-snapshots/cypress/e2e/store-spec.cy.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,14 @@ describe('Vuex store', () => {
138138

139139
it('starts typing after delayed server response', () => {
140140
// this will force new todo item to be added only after a delay
141-
cy.server()
142-
cy.route({
143-
method: 'POST',
144-
url: '/todos',
145-
delay: 3000,
146-
response: {},
147-
})
141+
cy.intercept(
142+
'POST',
143+
'/todos',
144+
{
145+
delay: 3000,
146+
body: {},
147+
}
148+
)
148149

149150
const title = 'first todo'
150151

@@ -249,13 +250,14 @@ describe('Store actions', () => {
249250
it('changes the state after delay', () => {
250251
// this will force store action "setNewTodo" to commit
251252
// change to the store only after 3 seconds
252-
// cy.server()
253-
cy.route({
254-
method: 'POST',
255-
url: '/todos',
256-
delay: 3000,
257-
response: {},
258-
}).as('post')
253+
cy.intercept(
254+
'POST',
255+
'/todos',
256+
{
257+
delay: 3000,
258+
body: {},
259+
}
260+
).as('post')
259261

260262
getStore().then((store) => {
261263
store.dispatch('setNewTodo', 'a new todo')
@@ -287,11 +289,7 @@ describe('Store actions', () => {
287289
})
288290

289291
it('calls server', () => {
290-
cy.server()
291-
cy.route({
292-
method: 'POST',
293-
url: '/todos',
294-
}).as('postTodo')
292+
cy.intercept('POST', '/todos').as('postTodo')
295293

296294
getStore().then((store) => {
297295
store.dispatch('setNewTodo', 'a new todo')
@@ -306,13 +304,14 @@ describe('Store actions', () => {
306304
})
307305

308306
it('calls server with delay', () => {
309-
cy.server()
310-
cy.route({
311-
method: 'POST',
312-
url: '/todos',
313-
delay: 3000,
314-
response: {},
315-
}).as('postTodo')
307+
cy.intercept(
308+
'POST',
309+
'/todos',
310+
{
311+
delay: 3000,
312+
body: {},
313+
}
314+
).as('postTodo')
316315

317316
getStore().then((store) => {
318317
store.dispatch('setNewTodo', 'a new todo')

examples/blogs__e2e-snapshots/cypress/support/utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export const visit = (skipWaiting) => {
2121

2222
console.log('visit will wait for initial todos', waitForInitialLoad)
2323
if (waitForInitialLoad) {
24-
cy.server()
25-
cy.route('/todos').as('initialTodos')
24+
cy.intercept('/todos').as('initialTodos')
2625
}
2726

2827
cy.visit('/')

examples/blogs__iframes/cypress/e2e/xhr-spec.cy.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ describe('Recipe: blogs__iframes', () => {
5555

5656
replaceIFrameFetchWithXhr()
5757
// spy on XHR before clicking the button
58-
cy.server()
59-
cy.route('/todos/1').as('getTodo')
58+
cy.intercept('/todos/1').as('getTodo')
6059

6160
getIframeBody().find('#run-button').should('have.text', 'Try it').click()
6261

@@ -79,8 +78,7 @@ describe('Recipe: blogs__iframes', () => {
7978

8079
replaceIFrameFetchWithXhr()
8180
// spy on XHR before clicking the button
82-
cy.server()
83-
cy.route('/todos/1', {
81+
cy.intercept('/todos/1', {
8482
completed: true,
8583
id: 1,
8684
title: 'write tests',

examples/blogs__vue-vuex-rest/cypress/e2e/api-spec.cy.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,16 @@ describe('Misc tests', () => {
6767
// waits for the alias "todos" to make sure
6868
// the application has actually made the request
6969
it('loads todos on start', () => {
70-
cy.server()
71-
cy.route('/todos').as('todos')
70+
cy.intercept('/todos').as('todos')
7271
cy.visit('/')
7372
cy.wait('@todos')
7473
})
7574

7675
// stubs expected API call with JSON response
7776
// from a fixture file
7877
it('loads todos from fixture file', () => {
79-
cy.server()
8078
// loads response from "cypress/fixtures/todos.json"
81-
cy.route('/todos', 'fixture:todos')
79+
cy.intercept('/todos', 'fixture:todos')
8280
cy.visit('/')
8381
getTodoItems()
8482
.should('have.length', 2)
@@ -88,8 +86,7 @@ describe('Misc tests', () => {
8886
})
8987

9088
it('initial todos', () => {
91-
cy.server()
92-
cy.route('/todos', [
89+
cy.intercept('/todos', [
9390
{
9491
title: 'mock first',
9592
completed: false,
@@ -159,13 +156,7 @@ describe('API', () => {
159156
})
160157

161158
it('is adding todo item', () => {
162-
cy.server()
163-
cy
164-
.route({
165-
method: 'POST',
166-
url: '/todos',
167-
})
168-
.as('postTodo')
159+
cy.intercept('POST', '/todos').as('postTodo')
169160

170161
// go through the UI
171162
enterTodo('first item') // id "1"
@@ -180,13 +171,7 @@ describe('API', () => {
180171
})
181172

182173
it('is deleting a todo item', () => {
183-
cy.server()
184-
cy
185-
.route({
186-
method: 'DELETE',
187-
url: '/todos/1',
188-
})
189-
.as('deleteTodo')
174+
cy.intercept('DELETE', '/todos/1').as('deleteTodo')
190175

191176
// go through the UI
192177
enterTodo('first item') // id "1"

examples/blogs__vue-vuex-rest/cypress/e2e/speed-spec.cy.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ describe('speed', () => {
8080
.should('have.length', 2)
8181

8282
// delete one item and confirm it was deleted
83-
cy.server()
84-
cy.route('DELETE', '/todos/*').as('delete')
83+
cy.intercept('DELETE', '/todos/*').as('delete')
8584
cy.contains('.todo-list li', 'be cool').find('.destroy').click({ force: true })
8685
cy.wait('@delete')
8786

@@ -94,11 +93,10 @@ describe('speed', () => {
9493
// there is no need to reset the backend data
9594

9695
// stub all network calls
97-
cy.server()
9896
// initially return an empty list of todos
99-
cy.route('GET', '/todos', [])
100-
cy.route('POST', '/todos', {})
101-
cy.route('DELETE', '/todos/*', {}).as('delete')
97+
cy.intercept('GET', '/todos', [])
98+
cy.intercept('POST', '/todos', {})
99+
cy.intercept('DELETE', '/todos/*', {}).as('delete')
102100

103101
// load the application
104102
cy.visit('/')
@@ -131,8 +129,7 @@ describe('speed', () => {
131129
})
132130

133131
// spy on the application's XHR calls
134-
cy.server()
135-
cy.route('DELETE', '/todos/*').as('delete')
132+
cy.intercept('DELETE', '/todos/*').as('delete')
136133

137134
// load the application
138135
cy.visit('/')
@@ -168,8 +165,7 @@ describe('speed', () => {
168165
})
169166

170167
// spy on the application's XHR calls
171-
cy.server()
172-
cy.route('DELETE', '/todos/*').as('delete')
168+
cy.intercept('DELETE', '/todos/*').as('delete')
173169

174170
// load the application
175171
cy.visit('/')

examples/blogs__vue-vuex-rest/cypress/e2e/store-spec.cy.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,14 @@ describe('Vuex store', () => {
162162

163163
it('starts typing after delayed server response', () => {
164164
// this will force new todo item to be added only after a delay
165-
cy.server()
166-
cy.route({
167-
method: 'POST',
168-
url: '/todos',
169-
delay: 3000,
170-
response: {},
171-
})
165+
cy.intercept(
166+
'POST',
167+
'/todos',
168+
{
169+
delay: 3000,
170+
body: {},
171+
}
172+
)
172173

173174
const title = 'first todo'
174175

@@ -332,13 +333,14 @@ describe('Store actions', () => {
332333
it('changes the state after delay', () => {
333334
// this will force store action "setNewTodo" to commit
334335
// change to the store only after 3 seconds
335-
cy.server()
336-
cy.route({
337-
method: 'POST',
338-
url: '/todos',
339-
delay: 3000,
340-
response: {},
341-
})
336+
cy.intercept(
337+
'POST',
338+
'/todos',
339+
{
340+
delay: 3000,
341+
body: {},
342+
}
343+
)
342344

343345
getStore().then((store) => {
344346
store.dispatch('setNewTodo', 'a new todo')
@@ -376,11 +378,7 @@ describe('Store actions', () => {
376378
})
377379

378380
it('calls server', () => {
379-
cy.server()
380-
cy.route({
381-
method: 'POST',
382-
url: '/todos',
383-
}).as('postTodo')
381+
cy.intercept('POST', '/todos').as('postTodo')
384382

385383
getStore().then((store) => {
386384
store.dispatch('setNewTodo', 'a new todo')
@@ -399,13 +397,14 @@ describe('Store actions', () => {
399397
})
400398

401399
it('calls server with delay', () => {
402-
cy.server()
403-
cy.route({
404-
method: 'POST',
405-
url: '/todos',
406-
delay: 3000,
407-
response: {},
408-
}).as('postTodo')
400+
cy.intercept(
401+
'POST',
402+
'/todos',
403+
{
404+
delay: 3000,
405+
body: {},
406+
}
407+
).as('postTodo')
409408

410409
getStore().then((store) => {
411410
store.dispatch('setNewTodo', 'a new todo')

examples/blogs__vue-vuex-rest/cypress/support/utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ export const visit = (skipWaiting) => {
2222

2323
console.log('visit will wait for initial todos', waitForInitialLoad)
2424
if (waitForInitialLoad) {
25-
cy.server()
26-
cy.route('/todos').as('initialTodos')
25+
cy.inspect('/todos').as('initialTodos')
2726
}
2827

2928
cy.visit('/')

examples/logging-in__single-sign-on/cypress/e2e/logging-in-single-sign-on-spec.cy.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,8 @@ describe('Logging In - Single Sign on', function () {
169169
cy.loginBySingleSignOn({ followRedirect: false })
170170
.then(responseToToken)
171171
.then((id_token) => {
172-
cy.server()
173172
// observe the "GET /config" call from the application
174-
cy.route('/config').as('getConfig')
173+
cy.inspect('/config').as('getConfig')
175174

176175
// now go visit our app
177176
cy.visit('/', {
@@ -240,9 +239,8 @@ describe('Logging In - Single Sign on', function () {
240239
// note again this test uses "function () { ... }" callback
241240
// in order to get access to the test context "this.token" saved above
242241

243-
cy.server()
244242
// observe the "GET /config" call from the application
245-
cy.route('/config').as('getConfig')
243+
cy.inspect('/config').as('getConfig')
246244

247245
cy.visit('/')
248246

0 commit comments

Comments
 (0)