Skip to content

Commit

Permalink
fix: removing cy.server and cy.route
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhenkes committed Nov 4, 2022
1 parent 73504f1 commit f2bee8a
Show file tree
Hide file tree
Showing 23 changed files with 45,281 additions and 256 deletions.
15 changes: 3 additions & 12 deletions examples/blogs__e2e-snapshots/cypress/e2e/api-spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ describe('via API', () => {

describe('initial', () => {
it('todos', () => {
cy.server()
cy.route('/todos', [
cy.intercept('/todos', [
{
title: 'mock first',
completed: false,
Expand Down Expand Up @@ -123,11 +122,7 @@ describe('API', () => {
})

it('is adding todo item', () => {
cy.server()
cy.route({
method: 'POST',
url: '/todos',
}).as('postTodo')
cy.intercept('POST', '/todos').as('postTodo')

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

it('is deleting a todo item', () => {
cy.server()
cy.route({
method: 'DELETE',
url: '/todos/1',
}).as('deleteTodo')
cy.intercept('DELETE', '/todos/1').as('deleteTodo')

// go through the UI
enterTodo('first item') // id "1"
Expand Down
51 changes: 25 additions & 26 deletions examples/blogs__e2e-snapshots/cypress/e2e/store-spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ describe('Vuex store', () => {

it('starts typing after delayed server response', () => {
// this will force new todo item to be added only after a delay
cy.server()
cy.route({
method: 'POST',
url: '/todos',
delay: 3000,
response: {},
})
cy.intercept(
'POST',
'/todos',
{
delay: 3000,
body: {},
}
)

const title = 'first todo'

Expand Down Expand Up @@ -249,13 +250,14 @@ describe('Store actions', () => {
it('changes the state after delay', () => {
// this will force store action "setNewTodo" to commit
// change to the store only after 3 seconds
// cy.server()
cy.route({
method: 'POST',
url: '/todos',
delay: 3000,
response: {},
}).as('post')
cy.intercept(
'POST',
'/todos',
{
delay: 3000,
body: {},
}
).as('post')

getStore().then((store) => {
store.dispatch('setNewTodo', 'a new todo')
Expand Down Expand Up @@ -287,11 +289,7 @@ describe('Store actions', () => {
})

it('calls server', () => {
cy.server()
cy.route({
method: 'POST',
url: '/todos',
}).as('postTodo')
cy.intercept('POST', '/todos').as('postTodo')

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

it('calls server with delay', () => {
cy.server()
cy.route({
method: 'POST',
url: '/todos',
delay: 3000,
response: {},
}).as('postTodo')
cy.intercept(
'POST',
'/todos',
{
delay: 3000,
body: {},
}
).as('postTodo')

getStore().then((store) => {
store.dispatch('setNewTodo', 'a new todo')
Expand Down
3 changes: 1 addition & 2 deletions examples/blogs__e2e-snapshots/cypress/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export const visit = (skipWaiting) => {

console.log('visit will wait for initial todos', waitForInitialLoad)
if (waitForInitialLoad) {
cy.server()
cy.route('/todos').as('initialTodos')
cy.intercept('/todos').as('initialTodos')
}

cy.visit('/')
Expand Down
6 changes: 2 additions & 4 deletions examples/blogs__iframes/cypress/e2e/xhr-spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ describe('Recipe: blogs__iframes', () => {

replaceIFrameFetchWithXhr()
// spy on XHR before clicking the button
cy.server()
cy.route('/todos/1').as('getTodo')
cy.intercept('/todos/1').as('getTodo')

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

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

replaceIFrameFetchWithXhr()
// spy on XHR before clicking the button
cy.server()
cy.route('/todos/1', {
cy.intercept('/todos/1', {
completed: true,
id: 1,
title: 'write tests',
Expand Down
25 changes: 5 additions & 20 deletions examples/blogs__vue-vuex-rest/cypress/e2e/api-spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,16 @@ describe('Misc tests', () => {
// waits for the alias "todos" to make sure
// the application has actually made the request
it('loads todos on start', () => {
cy.server()
cy.route('/todos').as('todos')
cy.intercept('/todos').as('todos')
cy.visit('/')
cy.wait('@todos')
})

// stubs expected API call with JSON response
// from a fixture file
it('loads todos from fixture file', () => {
cy.server()
// loads response from "cypress/fixtures/todos.json"
cy.route('/todos', 'fixture:todos')
cy.intercept('/todos', 'fixture:todos')
cy.visit('/')
getTodoItems()
.should('have.length', 2)
Expand All @@ -88,8 +86,7 @@ describe('Misc tests', () => {
})

it('initial todos', () => {
cy.server()
cy.route('/todos', [
cy.intercept('/todos', [
{
title: 'mock first',
completed: false,
Expand Down Expand Up @@ -159,13 +156,7 @@ describe('API', () => {
})

it('is adding todo item', () => {
cy.server()
cy
.route({
method: 'POST',
url: '/todos',
})
.as('postTodo')
cy.intercept('POST', '/todos').as('postTodo')

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

it('is deleting a todo item', () => {
cy.server()
cy
.route({
method: 'DELETE',
url: '/todos/1',
})
.as('deleteTodo')
cy.intercept('DELETE', '/todos/1').as('deleteTodo')

// go through the UI
enterTodo('first item') // id "1"
Expand Down
16 changes: 6 additions & 10 deletions examples/blogs__vue-vuex-rest/cypress/e2e/speed-spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ describe('speed', () => {
.should('have.length', 2)

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

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

// stub all network calls
cy.server()
// initially return an empty list of todos
cy.route('GET', '/todos', [])
cy.route('POST', '/todos', {})
cy.route('DELETE', '/todos/*', {}).as('delete')
cy.intercept('GET', '/todos', [])
cy.intercept('POST', '/todos', {})
cy.intercept('DELETE', '/todos/*', {}).as('delete')

// load the application
cy.visit('/')
Expand Down Expand Up @@ -131,8 +129,7 @@ describe('speed', () => {
})

// spy on the application's XHR calls
cy.server()
cy.route('DELETE', '/todos/*').as('delete')
cy.intercept('DELETE', '/todos/*').as('delete')

// load the application
cy.visit('/')
Expand Down Expand Up @@ -168,8 +165,7 @@ describe('speed', () => {
})

// spy on the application's XHR calls
cy.server()
cy.route('DELETE', '/todos/*').as('delete')
cy.intercept('DELETE', '/todos/*').as('delete')

// load the application
cy.visit('/')
Expand Down
51 changes: 25 additions & 26 deletions examples/blogs__vue-vuex-rest/cypress/e2e/store-spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ describe('Vuex store', () => {

it('starts typing after delayed server response', () => {
// this will force new todo item to be added only after a delay
cy.server()
cy.route({
method: 'POST',
url: '/todos',
delay: 3000,
response: {},
})
cy.intercept(
'POST',
'/todos',
{
delay: 3000,
body: {},
}
)

const title = 'first todo'

Expand Down Expand Up @@ -332,13 +333,14 @@ describe('Store actions', () => {
it('changes the state after delay', () => {
// this will force store action "setNewTodo" to commit
// change to the store only after 3 seconds
cy.server()
cy.route({
method: 'POST',
url: '/todos',
delay: 3000,
response: {},
})
cy.intercept(
'POST',
'/todos',
{
delay: 3000,
body: {},
}
)

getStore().then((store) => {
store.dispatch('setNewTodo', 'a new todo')
Expand Down Expand Up @@ -376,11 +378,7 @@ describe('Store actions', () => {
})

it('calls server', () => {
cy.server()
cy.route({
method: 'POST',
url: '/todos',
}).as('postTodo')
cy.intercept('POST', '/todos').as('postTodo')

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

it('calls server with delay', () => {
cy.server()
cy.route({
method: 'POST',
url: '/todos',
delay: 3000,
response: {},
}).as('postTodo')
cy.intercept(
'POST',
'/todos',
{
delay: 3000,
body: {},
}
).as('postTodo')

getStore().then((store) => {
store.dispatch('setNewTodo', 'a new todo')
Expand Down
3 changes: 1 addition & 2 deletions examples/blogs__vue-vuex-rest/cypress/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export const visit = (skipWaiting) => {

console.log('visit will wait for initial todos', waitForInitialLoad)
if (waitForInitialLoad) {
cy.server()
cy.route('/todos').as('initialTodos')
cy.inspect('/todos').as('initialTodos')
}

cy.visit('/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ describe('Logging In - Single Sign on', function () {
cy.loginBySingleSignOn({ followRedirect: false })
.then(responseToToken)
.then((id_token) => {
cy.server()
// observe the "GET /config" call from the application
cy.route('/config').as('getConfig')
cy.inspect('/config').as('getConfig')

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

cy.server()
// observe the "GET /config" call from the application
cy.route('/config').as('getConfig')
cy.inspect('/config').as('getConfig')

cy.visit('/')

Expand Down
Loading

0 comments on commit f2bee8a

Please sign in to comment.