Skip to content

Commit

Permalink
feat: deprecate cy.route(), remove experimentalNetworkStubbing flag (#…
Browse files Browse the repository at this point in the history
…9185)

Co-authored-by: Jennifer Shehane <[email protected]>
  • Loading branch information
flotwig and jennifer-shehane authored Nov 17, 2020
1 parent c385273 commit 3fec100
Show file tree
Hide file tree
Showing 21 changed files with 198 additions and 195 deletions.
5 changes: 0 additions & 5 deletions cli/schema/cypress.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,6 @@
"default": false,
"description": "Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement algorithm."
},
"experimentalNetworkStubbing": {
"type": "boolean",
"default": false,
"description": "Enables `cy.http()`, which can be used to dynamically intercept/stub/await any HTTP request or response (XHRs, fetch, beacons, etc.)"
},
"experimentalFetchPolyfill": {
"type": "boolean",
"default": false,
Expand Down
5 changes: 0 additions & 5 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2576,11 +2576,6 @@ declare namespace Cypress {
* @default false
*/
experimentalSourceRewriting: boolean
/**
* Enables `cy.http()`, which can be used to dynamically intercept/stub/await any HTTP request or response (XHRs, fetch, beacons, etc.)
* @default false
*/
experimentalNetworkStubbing: boolean
/**
* Number of times to retry a failed test.
* If a number is set, tests will retry in both runMode and openMode.
Expand Down
1 change: 0 additions & 1 deletion packages/desktop-gui/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"nodeVersion": "system",
"testFiles": "**/*_spec.{js,jsx}",
"experimentalComponentTesting": true,
"experimentalNetworkStubbing": true,
"componentFolder": "src",
"reporter": "../../node_modules/cypress-multi-reporters/index.js",
"reporterOptions": {
Expand Down
3 changes: 1 addition & 2 deletions packages/driver/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
"reporter": "cypress-multi-reporters",
"reporterOptions": {
"configFile": "../../mocha-reporter-config.json"
},
"experimentalNetworkStubbing": true
}
}
14 changes: 0 additions & 14 deletions packages/driver/cypress/integration/commands/net_stubbing_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,20 +309,6 @@ describe('network stubbing', { retries: 2 }, function () {
})
})

it('if experimentalNetworkStubbing is falsy', function (done) {
sinon.stub(Cypress, 'config').callThrough()
// @ts-ignore
.withArgs('experimentalNetworkStubbing').returns(false)

cy.on('fail', (err) => {
expect(err.message).to.contain('`cy.http()` requires experimental network mocking to be enabled.')
sinon.restore()
done()
})

cy.http('', '')
})

it('url must be a string or regexp', function (done) {
cy.on('fail', function (err) {
expect(err.message).to.include('`url` must be a string or a regular expression')
Expand Down
33 changes: 19 additions & 14 deletions packages/driver/cypress/integration/commands/xhr_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,15 @@ describe('src/cy/commands/xhr', () => {
})

context('#server', () => {
it('logs deprecation warning', () => {
cy.stub(Cypress.utils, 'warning')

cy.server()
.then(function () {
expect(Cypress.utils.warning).to.be.calledWithMatch(/^`cy\.server\(\)` has been deprecated and will be moved to a plugin in a future release\. Consider migrating to using `cy\.http\(\)` instead\./)
})
})

it('sets serverIsStubbed', () => {
cy.server().then(() => {
expect(cy.state('serverIsStubbed')).to.be.true
Expand Down Expand Up @@ -1261,6 +1270,15 @@ describe('src/cy/commands/xhr', () => {
})
})

it('logs deprecation warning', () => {
cy.stub(Cypress.utils, 'warning')

cy.route('*')
.then(function () {
expect(Cypress.utils.warning).to.be.calledWithMatch(/^`cy\.route\(\)` has been deprecated and will be moved to a plugin in a future release\. Consider migrating to using `cy\.http\(\)` instead\./)
})
})

it('accepts url, response', () => {
cy.route('/foo', {}).then(function () {
this.expectOptionsToBe({
Expand Down Expand Up @@ -1642,7 +1660,7 @@ describe('src/cy/commands/xhr', () => {

cy.route('GET', 'http://example.com/%E0%A4%A')
.then(() => {
expect(Cypress.utils.warning).to.not.be.called
expect(Cypress.utils.warning).to.not.be.calledWithMatch(/percent\-encoded characters/)
})
})

Expand All @@ -1654,19 +1672,6 @@ describe('src/cy/commands/xhr', () => {
})
})

describe('deprecations', () => {
beforeEach(function () {
this.warn = cy.spy(window.top.console, 'warn')
})

it('does not log on {force404: true}', () => {
cy.server({ force404: true })
.then(function () {
expect(this.warn).not.to.be.called
})
})
})

describe('request response alias', () => {
it('matches xhrs with lowercase methods', () => {
cy
Expand Down
7 changes: 1 addition & 6 deletions packages/driver/src/cy/commands/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let hasVisitedAboutBlank = null
let currentlyVisitingAboutBlank = null
let knownCommandCausedInstability = null

const REQUEST_URL_OPTS = 'auth failOnStatusCode retryOnNetworkFailure retryOnStatusCodeFailure method body headers selfProxy'
const REQUEST_URL_OPTS = 'auth failOnStatusCode retryOnNetworkFailure retryOnStatusCodeFailure method body headers'
.split(' ')

const VISIT_OPTS = 'url log onBeforeLoad onLoad timeout requestTimeout'
Expand Down Expand Up @@ -877,11 +877,6 @@ module.exports = (Commands, Cypress, cy, state, config) => {
url = url.replace(`${existingAuth}@`, '')
}

// hack to make cy.visits interceptable by network stubbing
if (Cypress.config('experimentalNetworkStubbing')) {
options.selfProxy = true
}

return requestUrl(url, options)
.then((resp = {}) => {
let { url, originalUrl, cookies, redirects, filePath } = resp
Expand Down
13 changes: 6 additions & 7 deletions packages/driver/src/cy/commands/waiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const throwErr = (arg) => {

module.exports = (Commands, Cypress, cy, state) => {
const isDynamicAliasingPossible = () => {
// dynamic aliasing is possible if cy.http is enabled and a route with dynamic interception has been defined
return Cypress.config('experimentalNetworkStubbing') && _.find(state('routes'), (route) => {
// dynamic aliasing is possible if a route with dynamic interception has been defined
return _.find(state('routes'), (route) => {
return _.isFunction(route.handler)
})
}
Expand Down Expand Up @@ -75,12 +75,11 @@ module.exports = (Commands, Cypress, cy, state) => {

options.type = type

if (Cypress.config('experimentalNetworkStubbing')) {
const req = waitForRoute(alias, state, type)
// check cy.http routes
const req = waitForRoute(alias, state, type)

if (req) {
return req
}
if (req) {
return req
}

// append .type to the alias
Expand Down
4 changes: 4 additions & 0 deletions packages/driver/src/cy/commands/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ module.exports = (Commands, Cypress, cy, state, config) => {

return Commands.addAll({
server (options) {
$errUtils.warnByPath('server.deprecated')

let userOptions = options

if (arguments.length === 0) {
Expand All @@ -351,6 +353,8 @@ module.exports = (Commands, Cypress, cy, state, config) => {
},

route (...args) {
$errUtils.warnByPath('route.deprecated')

// TODO:
// if we return a function which returns a promise
// then we should be handling potential timeout issues
Expand Down
4 changes: 0 additions & 4 deletions packages/driver/src/cy/net-stubbing/add-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@ export function addCommand (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy,
}

function http (matcher: RouteMatcher, handler?: RouteHandler | StringMatcher, arg2?: RouteHandler) {
if (!Cypress.config('experimentalNetworkStubbing')) {
return $errUtils.throwErrByPath('net_stubbing.http.needs_experimental')
}

function getMatcherOptions (): RouteMatcherOptions {
if (_.isString(matcher) && $utils.isValidHttpMethod(matcher) && isStringMatcher(handler)) {
// method, url, handler
Expand Down
14 changes: 8 additions & 6 deletions packages/driver/src/cypress/error_messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,12 +917,6 @@ module.exports = {
You passed: ${format(staticResponse)}`, 8)
},
http: {
needs_experimental: stripIndent`\
${cmd('http')} requires experimental network mocking to be enabled.
Set the \`experimentalNetworkStubbing\` config value to \`true\` to access this command.
Read more: https://on.cypress.io/experiments`,
invalid_handler: ({ handler }) => {
return stripIndent`\
${cmd('http')}'s \`handler\` argument must be a String, StaticResponse, or HttpController function.
Expand Down Expand Up @@ -1200,6 +1194,10 @@ module.exports = {
},

route: {
deprecated: {
message: `${cmd('route')} has been deprecated and will be moved to a plugin in a future release. Consider migrating to using ${cmd('http')} instead.`,
docsUrl: 'https://on.cypress.io/http',
},
failed_prerequisites: {
message: `${cmd('route')} cannot be invoked before starting the ${cmd('server')}`,
docsUrl: 'https://on.cypress.io/server',
Expand Down Expand Up @@ -1391,6 +1389,10 @@ module.exports = {
},

server: {
deprecated: {
message: `${cmd('server')} has been deprecated and will be moved to a plugin in a future release. Consider migrating to using ${cmd('http')} instead.`,
docsUrl: 'https://on.cypress.io/http',
},
invalid_argument: {
message: `${cmd('server')} accepts only an object literal as its argument.`,
docsUrl: 'https://on.cypress.io/server',
Expand Down
6 changes: 0 additions & 6 deletions packages/net-stubbing/lib/external-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,6 @@ declare global {
/**
* Use `cy.http()` to stub and intercept HTTP requests and responses.
*
* Note: this command is only available if you have set the `experimentalNetworkStubbing`
* configuration option to `true`.
*
* @see https://on.cypress.io/http
* @example
* cy.http('https://localhost:7777/users', [{id: 1, name: 'Pat'}])
Expand All @@ -355,9 +352,6 @@ declare global {
/**
* Use `cy.http()` to stub and intercept HTTP requests and responses.
*
* Note: this command is only available if you have set the `experimentalNetworkStubbing`
* configuration option to `true`.
*
* @see https://on.cypress.io/http
* @example
* cy.http('GET', 'http://foo.com/fruits', ['apple', 'banana', 'cherry'])
Expand Down
2 changes: 2 additions & 0 deletions packages/net-stubbing/lib/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export { InterceptResponse } from './intercept-response'

export { NetStubbingState } from './types'

export { getRouteForRequest } from './route-matching'

import { state } from './state'

export const netStubbingState = state
Loading

2 comments on commit 3fec100

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3fec100 Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.0.0/appveyor-v6.0-release-3fec10039713aa9b444e4ada1a6481b8392b3636/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3fec100 Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/6.0.0/appveyor-v6.0-release-3fec10039713aa9b444e4ada1a6481b8392b3636/cypress.tgz

Please sign in to comment.