Skip to content

Commit

Permalink
feat: remove deprecated cy.route2 command
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Jan 22, 2021
1 parent 36a4be0 commit 652cbac
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 44 deletions.
22 changes: 0 additions & 22 deletions packages/driver/cypress/integration/commands/net_stubbing_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,6 @@ describe('network stubbing', { retries: 2 }, function () {
cy.spy(Cypress.utils, 'warning')
})

context('cy.route2()', function () {
it('emits a warning', function () {
cy.route2('*')
.then(() => expect(Cypress.utils.warning).to.be.calledWith('`cy.route2()` was renamed to `cy.intercept()` and will be removed in a future release. Please update usages of `cy.route2()` to use `cy.intercept()` instead.'))
})

it('calls through to cy.intercept()', function (done) {
cy.route2('*', 'hello world').then(() => {
$.get('/abc123').done((responseText, _, xhr) => {
expect(responseText).to.eq('hello world')

done()
})
})
})

it('can be used with cy.wait', function () {
cy.route2('*', 'hello world').as('foo')
.then(() => $.get('/abc123')).wait('@foo')
})
})

context('cy.intercept()', function () {
beforeEach(function () {
// we don't use cy.spy() because it causes an infinite loop with logging events
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/querying.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ module.exports = (Commands, Cypress, cy, state) => {
return requests
}

if (['route2', 'intercept'].includes(command.get('name'))) {
if (command.get('name') === 'intercept') {
const requests = getAliasedRequests(alias, state)
// detect alias.all and alias.index
const specifier = /\.(all|[\d]+)$/.exec(selector)
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/waiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ module.exports = (Commands, Cypress, cy, state) => {
}

const isNetworkInterceptCommand = (command) => {
const commandsThatCreateNetworkIntercepts = ['route', 'route2', 'intercept']
const commandsThatCreateNetworkIntercepts = ['route', 'intercept']
const commandName = command.get('name')

return commandsThatCreateNetworkIntercepts.includes(commandName)
Expand Down
12 changes: 1 addition & 11 deletions packages/driver/src/cy/net-stubbing/add-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,6 @@ export function addCommand (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy,
return emitNetEvent('route:added', frame)
}

function route2 (...args) {
$errUtils.warnByPath('net_stubbing.route2_renamed')

// @ts-ignore
return intercept.apply(undefined, args)
}

function intercept (matcher: RouteMatcher, handler?: RouteHandler | StringMatcher, arg2?: RouteHandler) {
function getMatcherOptions (): RouteMatcherOptions {
if (_.isString(matcher) && $utils.isValidHttpMethod(matcher) && isStringMatcher(handler)) {
Expand Down Expand Up @@ -322,8 +315,5 @@ export function addCommand (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy,
.then(() => null)
}

Commands.addAll({
intercept,
route2,
})
Commands.addAll({ intercept })
}
1 change: 0 additions & 1 deletion packages/driver/src/cypress/error_messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,6 @@ module.exports = {
},

net_stubbing: {
route2_renamed: `${cmd('route2')} was renamed to ${cmd('intercept')} and will be removed in a future release. Please update usages of ${cmd('route2')} to use ${cmd('intercept')} instead.`,
invalid_static_response: ({ cmd, message, staticResponse }) => {
return cyStripIndent(`\
An invalid StaticResponse was supplied to \`${cmd}()\`. ${message}
Expand Down
8 changes: 0 additions & 8 deletions packages/net-stubbing/lib/external-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,6 @@ declare global {
* cy.intercept('GET', 'http://foo.com/fruits', ['apple', 'banana', 'cherry'])
*/
intercept(method: Method, url: RouteMatcher, response?: RouteHandler): Chainable<null>
/**
* @deprecated Use `cy.intercept()` instead.
*/
route2(url: RouteMatcher, response?: RouteHandler): Chainable<null>
/**
* @deprecated Use `cy.intercept()` instead.
*/
route2(method: Method, url: RouteMatcher, response?: RouteHandler): Chainable<null>
/**
* Wait for a specific request to complete.
*
Expand Down

0 comments on commit 652cbac

Please sign in to comment.