Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow separate request and response timeout overrides in cy.wait #2829

Merged
merged 2 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1514,13 +1514,13 @@ declare namespace Cypress {
*
* @see https://on.cypress.io/wait
*/
wait(alias: string, options?: Partial<Loggable & Timeoutable>): Chainable<WaitXHR>
wait(alias: string, options?: Partial<Loggable & Timeoutable & TimeoutableXHR>): Chainable<WaitXHR>
/**
* Wait for list of XHR requests to complete.
*
* @see https://on.cypress.io/wait
*/
wait(alias: string[], options?: Partial<Loggable & Timeoutable>): Chainable<WaitXHR[]>
wait(alias: string[], options?: Partial<Loggable & Timeoutable & TimeoutableXHR>): Chainable<WaitXHR[]>

/**
* Get the window object of the page that is currently active.
Expand Down Expand Up @@ -1647,6 +1647,26 @@ declare namespace Cypress {
timeout: number
}

/**
* Options that control how long the Test Runner waits for an XHR request and response to succeed
*/
interface TimeoutableXHR {
/**
* Time to wait for the request (ms)
*
* @default {@link Timeoutable#timeout}
* @see https://docs.cypress.io/guides/references/configuration.html#Timeouts
*/
requestTimeout: number,
/**
* Time to wait for the response (ms)
*
* @default {@link Timeoutable#timeout}
* @see https://docs.cypress.io/guides/references/configuration.html#Timeouts
*/
responseTimeout: number
}

/**
* Options to force an event, skipping Actionability check
* @see https://docs.cypress.io/guides/core-concepts/interacting-with-elements.html#Actionability
Expand Down
6 changes: 4 additions & 2 deletions packages/driver/src/cy/commands/waiting.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,19 @@ module.exports = (Commands, Cypress, cy, state, config) ->
## but slice out the error since we may set
## the error related to a previous xhr
timeout = options.timeout
requestTimeout = options.requestTimeout ? timeout
responseTimeout = options.responseTimeout ? timeout

[ index, num ] = getNumRequests(state, alias)

waitForRequest = ->
options = _.omit(options, "_runnableTimeout")
options.timeout = timeout ? Cypress.config("requestTimeout")
options.timeout = requestTimeout ? Cypress.config("requestTimeout")
checkForXhr(alias, "request", index, num, options)

waitForResponse = ->
options = _.omit(options, "_runnableTimeout")
options.timeout = timeout ? Cypress.config("responseTimeout")
options.timeout = responseTimeout ? Cypress.config("responseTimeout")
checkForXhr(alias, "response", index, num, options)

## if we were only waiting for the request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ describe "src/cy/commands/waiting", ->
.wait("@fetch").then ->
expect(cy.timeout()).to.eq 199

it "waits for requestTimeout override", (done) ->
cy.on "command:retry", (options) ->
expect(options.type).to.eq("request")
expect(options.timeout).to.eq(199)
done()

cy
.server()
.route("GET", "*", {}).as("fetch")
.wait("@fetch", {requestTimeout: 199})

it "waits for responseTimeout", (done) ->
Cypress.config("responseTimeout", 299)

Expand All @@ -125,6 +136,41 @@ describe "src/cy/commands/waiting", ->
null
.wait("@fetch")

it "waits for responseTimeout override", (done) ->
cy.on "command:retry", (options) ->
expect(options.type).to.eq("response")
expect(options.timeout).to.eq(299)
done()

cy
.server({delay: 100})
.route("GET", "*", {}).as("fetch")
.window().then (win) ->
win.$.get("/foo")
null
.wait("@fetch", {responseTimeout: 299})

it "waits for requestTimeout and responseTimeout override", (done) ->
retryCount = 0
cy.on "command:retry", (options) ->
retryCount++
if retryCount == 1
expect(options.type).to.eq("request")
expect(options.timeout).to.eq(100)

## trigger request to move onto response timeout verification
win = cy.state("window")
win.$.get("/foo")
else if retryCount == 2
expect(options.type).to.eq("response")
expect(options.timeout).to.eq(299)
done()

cy
.server({delay: 100})
.route("GET", "*", {}).as("fetch")
.wait("@fetch", {requestTimeout: 100, responseTimeout: 299})

## https://github.com/cypress-io/cypress/issues/369
it "does not mutate 2nd route methods when using shorthand route", ->
cy
Expand Down