Skip to content

Commit

Permalink
breaking: Remove deprecated delayMs option of cy.intercept (#30463)
Browse files Browse the repository at this point in the history
* Remove deprecated delayMs property from cy.intercept

BREAKING: Remove deprecated delayMs property from cy.intercept

* Update test to new signature

* Add changelog entry
  • Loading branch information
jennifer-shehane authored Oct 30, 2024
1 parent f9be7ba commit a8f64a3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 42 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ _Released 12/3/2024 (PENDING)_

- Removed support for Node.js 16 and Node.js 21. Addresses [#29930](https://github.com/cypress-io/cypress/issues/29930).
- Prebuilt binaries for Linux are no longer compatible with Linux distributions based on glibc <2.28, for example: Ubuntu 14-18, RHEL 7, CentOS 7, Amazon Linux 2. Addresses [#29601](https://github.com/cypress-io/cypress/issues/29601).
- The `delayMs` option of `cy.intercept()` has been removed. This option was deprecated in Cypress 6.4.0. Please use the `delay` option instead. Addressed in [#30463](https://github.com/cypress-io/cypress/pull/30463).
- The `experimentalFetchPolyfill` configuration option was removed. This option was deprecated in Cypress 6.0.0. We recommend using `cy.intercept()` for handling fetch requests. Addressed in [#30466](https://github.com/cypress-io/cypress/pull/30466).
- We removed yielding the second argument of `before:browser:launch` as an array of browser arguments. This behavior has been deprecated since Cypress 4.0.0. Addressed in [#30460](https://github.com/cypress-io/cypress/pull/30460).
- The `cypress open-ct` and `cypress run-ct` CLI commands were removed. Please use `cypress open --component` or `cypress run --component` respectively instead. Addressed in [#30456](https://github.com/cypress-io/cypress/pull/30456)
Expand Down
17 changes: 0 additions & 17 deletions packages/driver/cypress/e2e/commands/net_stubbing.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1697,23 +1697,6 @@ describe('network stubbing', { retries: 15 }, function () {
})
})

// TODO: fix flaky test https://github.com/cypress-io/cypress/issues/23404
it('can delay with deprecated delayMs param', { retries: 15 }, function () {
const delayMs = 250

cy.intercept('/timeout*', (req) => {
this.start = Date.now()

req.reply({
delayMs,
})
}).then(() => {
return $.get('/timeout').then((responseText) => {
expect(Date.now() - this.start).to.be.closeTo(delayMs + 100, 100)
})
})
})

// @see https://github.com/cypress-io/cypress/issues/14446
// TODO: fix flaky test https://github.com/cypress-io/cypress/issues/23406
it('should delay the same amount on every response', { retries: 15 }, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const {
describe('driver/src/cy/net-stubbing/static-response-utils', () => {
describe('.getBackendStaticResponse', () => {
describe('delay', () => {
it('does not set delay when delayMS is not provided', () => {
it('does not set delay when delay is not provided', () => {
const staticResponse = getBackendStaticResponse({})

expect(staticResponse).to.not.have.property('delay')
})

it('sets delay', () => {
const staticResponse = getBackendStaticResponse({ delayMs: 200 })
const staticResponse = getBackendStaticResponse({ delay: 200 })

expect(staticResponse).to.have.property('delay', 200)
})
Expand Down
19 changes: 3 additions & 16 deletions packages/driver/src/cy/net-stubbing/static-response-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import $errUtils from '../../cypress/error_utils'

// user-facing StaticResponse only
export const STATIC_RESPONSE_KEYS: (keyof StaticResponse)[] = ['body', 'fixture', 'statusCode', 'headers', 'forceNetworkError', 'throttleKbps', 'delay', 'delayMs']
export const STATIC_RESPONSE_KEYS: (keyof StaticResponse)[] = ['body', 'fixture', 'statusCode', 'headers', 'forceNetworkError', 'throttleKbps', 'delay']

export const STATIC_RESPONSE_WITH_OPTIONS_KEYS: (keyof StaticResponseWithOptions)[] = [...STATIC_RESPONSE_KEYS, 'log']

Expand All @@ -21,7 +21,7 @@ export function validateStaticResponse (cmd: string, staticResponse: StaticRespo
$errUtils.throwErrByPath('net_stubbing.invalid_static_response', { args: { cmd, message, staticResponse } })
}

const { body, fixture, statusCode, headers, forceNetworkError, throttleKbps, delay, delayMs } = staticResponse
const { body, fixture, statusCode, headers, forceNetworkError, throttleKbps, delay } = staticResponse

if (forceNetworkError && (body || statusCode || headers)) {
err('`forceNetworkError`, if passed, must be the only option in the StaticResponse.')
Expand Down Expand Up @@ -53,14 +53,6 @@ export function validateStaticResponse (cmd: string, staticResponse: StaticRespo
err('`throttleKbps` must be a finite, positive number.')
}

if (delayMs && delay) {
err('`delayMs` and `delay` cannot both be set.')
}

if (delayMs && (!_.isFinite(delayMs) || delayMs < 0)) {
err('`delayMs` must be a finite, positive number.')
}

if (delay && (!_.isFinite(delay) || delay < 0)) {
err('`delay` must be a finite, positive number.')
}
Expand Down Expand Up @@ -106,12 +98,7 @@ function getFixtureOpts (fixture: string): FixtureOpts {
}

export function getBackendStaticResponse (staticResponse: Readonly<StaticResponseWithOptions>): BackendStaticResponseWithArrayBuffer {
const backendStaticResponse: BackendStaticResponseWithArrayBuffer = _.omit(staticResponse, 'body', 'fixture', 'delayMs', 'log')

if (staticResponse.delayMs) {
// support deprecated `delayMs` usage
backendStaticResponse.delay = staticResponse.delayMs
}
const backendStaticResponse: BackendStaticResponseWithArrayBuffer = _.omit(staticResponse, 'body', 'fixture', 'log')

if (staticResponse.fixture) {
backendStaticResponse.fixture = getFixtureOpts(staticResponse.fixture)
Expand Down
8 changes: 1 addition & 7 deletions packages/net-stubbing/lib/external-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,7 @@ export type StaticResponseWithOptions = StaticResponse & InterceptOptions
/**
* Describes a response that will be sent back to the browser to fulfill the request.
*/
export type StaticResponse = GenericStaticResponse<string, string | object | boolean | ArrayBuffer | null> & {
/**
* Milliseconds to delay before the response is sent.
* @deprecated Use `delay` instead of `delayMs`.
*/
delayMs?: number
}
export type StaticResponse = GenericStaticResponse<string, string | object | boolean | ArrayBuffer | null>

export interface GenericStaticResponse<Fixture, Body> {
/**
Expand Down

0 comments on commit a8f64a3

Please sign in to comment.