Skip to content

Commit

Permalink
Fix timeout progress bar for cy.wait (#7882)
Browse files Browse the repository at this point in the history
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
  • Loading branch information
panzarino and jennifer-shehane committed Jul 20, 2020
1 parent 86a2feb commit 1083323
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
97 changes: 97 additions & 0 deletions packages/driver/cypress/integration/commands/waiting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,103 @@ describe('src/cy/commands/waiting', () => {
})
})
})

describe('timeouts', function () {
it('sets default requestTimeout', {
requestTimeout: 199,
}, function (done) {
cy.on('command:retry', () => {
expect(this.lastLog.get('timeout')).to.eq(199)

done()
})

cy
.server()
.route('GET', '*', {}).as('fetch')
.wait('@fetch')
})

it('sets custom requestTimeout', function (done) {
cy.on('command:retry', () => {
expect(this.lastLog.get('timeout')).to.eq(199)

done()
})

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

it('sets default responseTimeout', {
responseTimeout: 299,
}, function (done) {
cy.on('command:retry', () => {
expect(this.lastLog.get('timeout')).to.eq(299)

done()
})

cy
.server({ delay: 100 })
.route('GET', '*', {}).as('fetch')
.window().then((win) => {
xhrGet(win, '/foo')

return null
})
.wait('@fetch')
})

it('sets custom responseTimeout', function (done) {
cy.on('command:retry', () => {
expect(this.lastLog.get('timeout')).to.eq(299)

done()
})

cy
.server({ delay: 100 })
.route('GET', '*', {}).as('fetch')
.window().then((win) => {
xhrGet(win, '/foo')

return null
})
.wait('@fetch', { responseTimeout: 299 })
})

it('updates to requestTimeout and responseTimeout at the proper times', function (done) {
let log
let retryCount = 0

cy.on('command:retry', () => {
log = log || this.lastLog
retryCount++
if (retryCount === 1) {
expect(log.get('timeout')).to.eq(100)

// trigger request to move onto response timeout verification
const win = cy.state('window')

xhrGet(win, '/foo')
}

if (retryCount === 2) {
expect(log.get('timeout')).to.eq(299)

done()
}
})

cy
.server({ delay: 100 })
.route('GET', '*', {}).as('fetch')
.wait('@fetch', { requestTimeout: 100, responseTimeout: 299 })
})
})
})
})
})
11 changes: 9 additions & 2 deletions packages/driver/src/cy/commands/waiting.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = (Commands, Cypress, cy, state) => {

if (options.log !== false) {
options._log = Cypress.log({
timeout: cy.timeout(),
timeout: ms,
consoleProps () {
return {
'Waited For': `${ms}ms before continuing`,
Expand All @@ -55,7 +55,6 @@ module.exports = (Commands, Cypress, cy, state) => {

if (options.log !== false) {
log = options._log = Cypress.log({
timeout: options.timeout,
type: 'parent',
aliasType: 'route',
options: userOptions,
Expand Down Expand Up @@ -156,13 +155,21 @@ module.exports = (Commands, Cypress, cy, state) => {
options = _.omit(options, '_runnableTimeout')
options.timeout = requestTimeout || Cypress.config('requestTimeout')

if (log) {
log.set('timeout', options.timeout)
}

return checkForXhr(alias, 'request', index, num, options)
}

const waitForResponse = () => {
options = _.omit(options, '_runnableTimeout')
options.timeout = responseTimeout || Cypress.config('responseTimeout')

if (log) {
log.set('timeout', options.timeout)
}

return checkForXhr(alias, 'response', index, num, options)
}

Expand Down
1 change: 1 addition & 0 deletions packages/reporter/src/commands/command-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default class Command extends Instrument {
this.numElements = props.numElements
this.renderProps = props.renderProps || {}
this.visible = props.visible
this.timeout = props.timeout

this._checkLongRunning()
}
Expand Down
3 changes: 2 additions & 1 deletion packages/reporter/src/commands/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ const Progress = observer(({ model }: ProgressProps) => {
const timeRemaining = model.timeout ? model.timeout - timeElapsed : 0
const percentageRemaining = timeRemaining / model.timeout * 100 || 0

// we add a key to the span to ensure a rerender and restart of the animation on change
return (
<div className='command-progress'>
<span style={{ animationDuration: `${timeRemaining}ms`, width: `${percentageRemaining}%` }} />
<span style={{ animationDuration: `${timeRemaining}ms`, width: `${percentageRemaining}%` }} key={timeRemaining} />
</div>
)
})
Expand Down

4 comments on commit 1083323

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1083323 Jul 20, 2020

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/linux-x64/circle-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-399888/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/circle-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-399885/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1083323 Jul 20, 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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-ia32/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.10.1/win32-ia32/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-ia32/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-ia32/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1083323 Jul 20, 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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-x64/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.10.1/win32-x64/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-x64/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-x64/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-34188852/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1083323 Jul 20, 2020

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/darwin-x64/circle-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-399982/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/circle-develop-10833232895939dbc2b6bdcdaa08eb8f8770bba8-399913/cypress.tgz

Please sign in to comment.