Skip to content

Commit 2f18a8c

Browse files
mjhenkesBlue Fflotwig
authored
fix: remove cypress.server.defaults, cy.server and cy.route (#24411)
* fix: remove server and route commands * This won't totally pass but it's a step in the right direction. * Should be down to only two failing tests due to abort. * fix the alias.<thing> api for intercept to be equivalent to route. * adjust timeouts to reduce flake, ideally * skip xhr abort tests * More clean up * Increase timeout * trick next version * fix unit tests probably * yeah sure * Apply suggestions from code review Co-authored-by: Blue F <blue@cypress.io> * remove addXhrLog * Remove more usage of XHR stemming from proxy-logging * Remove a couple of files that found their way back with the merge from release/12.0.0 * remove more server types * increase timeouts again to prevent flake Co-authored-by: Blue F <blue@cypress.io> Co-authored-by: Zach Bloomquist <git@chary.us>
1 parent 954be79 commit 2f18a8c

Some content is hidden

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

55 files changed

+367
-5546
lines changed

cli/types/cypress.d.ts

-133
Original file line numberDiff line numberDiff line change
@@ -591,13 +591,6 @@ declare namespace Cypress {
591591
defaults(options: Partial<KeyboardDefaultsOptions>): void
592592
}
593593

594-
/**
595-
* @see https://on.cypress.io/api/api-server
596-
*/
597-
Server: {
598-
defaults(options: Partial<ServerOptions>): void
599-
}
600-
601594
/**
602595
* @see https://on.cypress.io/screenshot-api
603596
*/
@@ -1665,66 +1658,6 @@ declare namespace Cypress {
16651658
*/
16661659
root<E extends Node = HTMLHtmlElement>(options?: Partial<Loggable>): Chainable<JQuery<E>> // can't do better typing unless we ignore the `.within()` case
16671660

1668-
/**
1669-
* @deprecated Use `cy.intercept()` instead.
1670-
*
1671-
* Use `cy.route()` to manage the behavior of network requests.
1672-
* @see https://on.cypress.io/route
1673-
* @example
1674-
* cy.server()
1675-
* cy.route('https://localhost:7777/users', [{id: 1, name: 'Pat'}])
1676-
*/
1677-
route(url: string | RegExp, response?: string | object): Chainable<null>
1678-
/**
1679-
* @deprecated Use `cy.intercept()` instead.
1680-
*
1681-
* Spy or stub request with specific method and url.
1682-
*
1683-
* @see https://on.cypress.io/route
1684-
* @example
1685-
* cy.server()
1686-
* // spy on POST /todos requests
1687-
* cy.route('POST', '/todos').as('add-todo')
1688-
*/
1689-
route(method: string, url: string | RegExp, response?: string | object): Chainable<null>
1690-
/**
1691-
* @deprecated Use `cy.intercept()` instead.
1692-
*
1693-
* Set a route by returning an object literal from a callback function.
1694-
* Functions that return a Promise will automatically be awaited.
1695-
*
1696-
* @see https://on.cypress.io/route
1697-
* @example
1698-
* cy.server()
1699-
* cy.route(() => {
1700-
* // your logic here
1701-
* // return an appropriate routing object here
1702-
* return {
1703-
* method: 'POST',
1704-
* url: '/comments',
1705-
* response: this.commentsFixture
1706-
* }
1707-
* })
1708-
*/
1709-
route(fn: () => RouteOptions): Chainable<null>
1710-
/**
1711-
* @deprecated Use `cy.intercept()` instead.
1712-
*
1713-
* Spy or stub a given route.
1714-
*
1715-
* @see https://on.cypress.io/route
1716-
* @example
1717-
* cy.server()
1718-
* cy.route({
1719-
* method: 'DELETE',
1720-
* url: '/users',
1721-
* status: 412,
1722-
* delay: 1000
1723-
* // and other options, see documentation
1724-
* })
1725-
*/
1726-
route(options: Partial<RouteOptions>): Chainable<null>
1727-
17281661
/**
17291662
* Take a screenshot of the application under test and the Cypress Command Log.
17301663
*
@@ -1770,26 +1703,6 @@ declare namespace Cypress {
17701703
*/
17711704
select(valueOrTextOrIndex: string | number | Array<string | number>, options?: Partial<SelectOptions>): Chainable<Subject>
17721705

1773-
/**
1774-
* @deprecated Use `cy.intercept()` instead.
1775-
*
1776-
* Start a server to begin routing responses to `cy.route()` and `cy.request()`.
1777-
*
1778-
* @example
1779-
* // start server
1780-
* cy.server()
1781-
* // get default server options
1782-
* cy.server().should((server) => {
1783-
* expect(server.delay).to.eq(0)
1784-
* expect(server.method).to.eq('GET')
1785-
* expect(server.status).to.eq(200)
1786-
* // and many others options
1787-
* })
1788-
*
1789-
* @see https://on.cypress.io/server
1790-
*/
1791-
server(options?: Partial<ServerOptions>): Chainable<ServerOptions>
1792-
17931706
/**
17941707
* Set a browser cookie.
17951708
*
@@ -3040,8 +2953,6 @@ declare namespace Cypress {
30402953
socketIoRoute: string
30412954
spec: Cypress['spec'] | null
30422955
specs: Array<Cypress['spec']>
3043-
xhrRoute: string
3044-
xhrUrl: string
30452956
}
30462957

30472958
interface TestConfigOverrides extends Partial<Pick<ConfigOptions, 'animationDistanceThreshold' | 'blockHosts' | 'defaultCommandTimeout' | 'env' | 'execTimeout' | 'includeShadowDom' | 'numTestsKeptInMemory' | 'pageLoadTimeout' | 'redirectionLimit' | 'requestTimeout' | 'responseTimeout' | 'retries' | 'screenshotOnRunFailure' | 'slowTestThreshold' | 'scrollBehavior' | 'taskTimeout' | 'viewportHeight' | 'viewportWidth' | 'waitForAnimations'>>, Partial<Pick<ResolvedConfigOptions, 'baseUrl'>> {
@@ -3289,28 +3200,6 @@ declare namespace Cypress {
32893200
interval: number
32903201
}
32913202

3292-
/**
3293-
* Setting default options for cy.server()
3294-
* @see https://on.cypress.io/server
3295-
*/
3296-
interface ServerOptions {
3297-
delay: number
3298-
method: HttpMethod
3299-
status: number
3300-
headers: object
3301-
response: any
3302-
onRequest(...args: any[]): void
3303-
onResponse(...args: any[]): void
3304-
onAbort(...args: any[]): void
3305-
enable: boolean
3306-
force404: boolean
3307-
urlMatchingOptions: object
3308-
ignore(xhr: Request): void
3309-
onAnyRequest(route: RouteOptions, proxy: any): void
3310-
onAnyResponse(route: RouteOptions, proxy: any): void
3311-
onAnyAbort(route: RouteOptions, proxy: any): void
3312-
}
3313-
33143203
interface Session {
33153204
// Clear all saved sessions and re-run the current spec file.
33163205
clearAllSavedSessions: () => Promise<void>
@@ -5947,28 +5836,6 @@ declare namespace Cypress {
59475836
viewportHeight: number
59485837
}
59495838

5950-
interface WaitXHR {
5951-
duration: number
5952-
id: string
5953-
method: HttpMethod
5954-
request: {
5955-
body: string | ObjectLike
5956-
headers: ObjectLike
5957-
}
5958-
requestBody: WaitXHR['request']['body']
5959-
requestHeaders: WaitXHR['request']['headers']
5960-
response: {
5961-
body: string | ObjectLike
5962-
headers: ObjectLike
5963-
}
5964-
responseBody: WaitXHR['response']['body']
5965-
responseHeaders: WaitXHR['response']['headers']
5966-
status: number
5967-
statusMessage: string
5968-
url: string
5969-
xhr: XMLHttpRequest
5970-
}
5971-
59725839
type Encodings = 'ascii' | 'base64' | 'binary' | 'hex' | 'latin1' | 'utf8' | 'utf-8' | 'ucs2' | 'ucs-2' | 'utf16le' | 'utf-16le' | null
59735840
type PositionType = 'topLeft' | 'top' | 'topRight' | 'left' | 'center' | 'right' | 'bottomLeft' | 'bottom' | 'bottomRight'
59745841
type ViewportPreset = 'macbook-16' | 'macbook-15' | 'macbook-13' | 'macbook-11' | 'ipad-2' | 'ipad-mini' | 'iphone-xr' | 'iphone-x' | 'iphone-6+' | 'iphone-se2' | 'iphone-8' | 'iphone-7' | 'iphone-6' | 'iphone-5' | 'iphone-4' | 'iphone-3' | 'samsung-s10' | 'samsung-note9'

cli/types/tests/kitchen-sink.ts

-15
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,13 @@ result // $ExpectType boolean
1818

1919
Cypress.minimatch('/users/1/comments', '/users/*/comments') // $ExpectType boolean
2020

21-
// check if cy.server() yields default server options
22-
cy.server().should((server) => {
23-
server // $ExpectType ServerOptions
24-
expect(server.delay).to.eq(0)
25-
expect(server.method).to.eq('GET')
26-
expect(server.status).to.eq(200)
27-
})
28-
2921
cy.visit('https://www.acme.com/', {
3022
auth: {
3123
username: 'wile',
3224
password: 'coyote'
3325
}
3426
})
3527

36-
const serverOptions: Partial<Cypress.ServerOptions> = {
37-
delay: 100,
38-
ignore: () => true
39-
}
40-
41-
cy.server(serverOptions)
42-
4328
Cypress.spec.name // $ExpectType string
4429
Cypress.spec.relative // $ExpectType string
4530
Cypress.spec.absolute // $ExpectType string

npm/react/cypress/component/advanced/testing-lib-example/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ You can install and bring [Testing library/Cypress](https://testing-library.com/
77

88
```js
99
it('loads and displays greeting (testing-lib)', () => {
10-
cy.server()
11-
cy.route('/greeting', { greeting: 'Hello there' }).as('greet')
10+
cy.intercept('/greeting', { greeting: 'Hello there' }).as('greet')
1211

1312
const url = '/greeting'
1413
mount(<Fetch url={url} />)
@@ -19,7 +18,7 @@ it('loads and displays greeting (testing-lib)', () => {
1918
cy.findByRole('heading').should('have.text', 'Hello there')
2019
cy.findByRole('button').should('be.disabled')
2120
cy.get('@greet')
22-
.its('url')
21+
.its('response.url')
2322
.should('match', /\/greeting$/)
2423
})
2524
```

npm/react/cypress/component/advanced/testing-lib-example/spec.cy.jsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { mount } from '@cypress/react'
33
import Fetcher from './fetcher'
44

55
it('loads and displays greeting', () => {
6-
cy.server()
7-
cy.route('/greeting', { greeting: 'Hello there' }).as('greet')
6+
cy.intercept('/greeting', { greeting: 'Hello there' }).as('greet')
87

98
const url = '/greeting'
109

@@ -14,6 +13,6 @@ it('loads and displays greeting', () => {
1413
cy.get('[role=heading]').should('have.text', 'Hello there')
1514
cy.get('[role=button]').should('be.disabled')
1615
cy.get('@greet')
17-
.its('url')
16+
.its('response.url')
1817
.should('match', /\/greeting$/)
1918
})

npm/react/cypress/component/advanced/testing-lib-example/testing-lib.cy.jsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import Fetcher from './fetcher'
77

88
// NOTE: this doesn't work because of update to the @testing/library v7. Looks like build issue with current webpack config
99
it.skip('loads and displays greeting (testing-lib)', () => {
10-
cy.server()
11-
cy.route('/greeting', { greeting: 'Hello there' }).as('greet')
10+
cy.intercept('/greeting', { greeting: 'Hello there' }).as('greet')
1211

1312
const url = '/greeting'
1413

@@ -21,6 +20,6 @@ it.skip('loads and displays greeting (testing-lib)', () => {
2120
cy.findByRole('heading').should('have.text', 'Hello there')
2221
cy.findByRole('button').should('be.disabled')
2322
cy.get('@greet')
24-
.its('url')
23+
.its('response.url')
2524
.should('match', /\/greeting$/)
2625
})

npm/react/cypress/component/basic/network/1-users.cy.jsx

+5-13
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@ context('Users', () => {
1515
})
1616

1717
describe('Network State', () => {
18-
beforeEach(() => {
19-
cy.server()
20-
// mount the component after defining routes in tests
21-
// preventing race conditions where you wait on untouched routes
22-
})
23-
2418
it('can inspect real data in XHR', () => {
25-
cy.route('/users?_limit=3').as('users')
19+
cy.intercept('/users?_limit=3').as('users')
2620
mount(<Users />)
2721
cy.wait('@users')
2822
.its('response.body')
@@ -34,7 +28,7 @@ context('Users', () => {
3428
it('can display mock XHR response', () => {
3529
const users = [{ id: 1, name: 'foo' }]
3630

37-
cy.route('GET', '/users?_limit=3', users).as('users')
31+
cy.intercept('GET', '/users?_limit=3', users).as('users')
3832
mount(<Users />)
3933
cy.get('li')
4034
.should('have.length', 1)
@@ -45,7 +39,7 @@ context('Users', () => {
4539
it('can inspect mocked XHR', () => {
4640
const users = [{ id: 1, name: 'foo' }]
4741

48-
cy.route('GET', '/users?_limit=3', users).as('users')
42+
cy.intercept('GET', '/users?_limit=3', users).as('users')
4943
mount(<Users />)
5044
cy.wait('@users')
5145
.its('response.body')
@@ -55,10 +49,8 @@ context('Users', () => {
5549
it('can delay and wait on XHR', () => {
5650
const users = [{ id: 1, name: 'foo' }]
5751

58-
cy.route({
59-
method: 'GET',
60-
url: '/users?_limit=3',
61-
response: users,
52+
cy.intercept('GET', '/users?_limit=3', {
53+
body: users,
6254
delay: 1000,
6355
}).as('users')
6456

npm/react/cypress/component/basic/network/2-users-fetch.cy.jsx

+5-13
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,9 @@ describe('Users with Fetch', () => {
1313

1414
// https://github.com/bahmutov/@cypress/react/issues/347
1515
context('mocking', () => {
16-
beforeEach(() => {
17-
cy.server()
18-
// mount the component after defining routes in tests
19-
// preventing race conditions where you wait on untouched routes
20-
})
21-
2216
it('can inspect real data from the server', () => {
2317
// spy on the request
24-
cy.route('/users?_limit=3').as('users')
18+
cy.intercept('/users?_limit=3').as('users')
2519
mount(<Users />)
2620
cy.wait('@users')
2721
.its('response.body')
@@ -34,7 +28,7 @@ describe('Users with Fetch', () => {
3428
const users = [{ id: 1, name: 'foo' }]
3529

3630
// stub the request
37-
cy.route('GET', '/users?_limit=3', users).as('users')
31+
cy.intercept('GET', '/users?_limit=3', users).as('users')
3832
mount(<Users />)
3933
cy.get('li')
4034
.should('have.length', 1)
@@ -45,7 +39,7 @@ describe('Users with Fetch', () => {
4539
it('can inspect mocked network reaponse', () => {
4640
const users = [{ id: 1, name: 'foo' }]
4741

48-
cy.route('GET', '/users?_limit=3', users).as('users')
42+
cy.intercept('GET', '/users?_limit=3', users).as('users')
4943
mount(<Users />)
5044
cy.wait('@users')
5145
.its('response.body')
@@ -55,10 +49,8 @@ describe('Users with Fetch', () => {
5549
it('can delay and wait on Ajax call', () => {
5650
const users = [{ id: 1, name: 'foo' }]
5751

58-
cy.route({
59-
method: 'GET',
60-
url: '/users?_limit=3',
61-
response: users,
52+
cy.intercept('GET', '/users?_limit=3', {
53+
body: users,
6254
delay: 1000,
6355
}).as('users')
6456

npm/vue/cypress/component/advanced/fetch-polyfill/Users.cy.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@ describe('Fetching users with polyfill', () => {
1010
})
1111

1212
it('can spy on the fetch requests', () => {
13-
cy.server()
14-
cy.route('/users?_limit=3').as('users')
13+
cy.intercept('/users?_limit=3').as('users')
1514
mount(Users)
1615
cy.wait('@users')
17-
.its('responseBody.length')
16+
.its('response.body.length')
1817
.then((length) => {
1918
cy.get('.user').should('have.length', length)
2019
})
2120
})
2221

2322
it('shows loading UI while fetch is happening', () => {
24-
cy.server()
25-
cy.route({
26-
url: '/users?_limit=3',
27-
response: 'fixture:users',
23+
cy.intercept('/users?_limit=3', {
24+
fixture: 'users',
2825
delay: 1000,
2926
})
3027

0 commit comments

Comments
 (0)