Skip to content

Commit

Permalink
feat: Add user's log option to cy.tick (#15586)
Browse files Browse the repository at this point in the history
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
  • Loading branch information
saturninoabril and jennifer-shehane committed Mar 20, 2021
1 parent e41cfc1 commit 35be2ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ declare namespace Cypress {
* // or use this shortcut
* cy.tick(5000).invoke('restore')
*/
tick(milliseconds: number): Chainable<Clock>
tick(milliseconds: number, options?: Partial<Loggable>): Chainable<Clock>

/**
* Get the `document.title` property of the page that is currently active.
Expand Down
9 changes: 9 additions & 0 deletions packages/driver/cypress/integration/commands/clock_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,15 @@ describe('src/cy/commands/clock', () => {
expect(log.get('snapshots')[1].name).to.equal('after')
})
})

it('does not emit when {log: false}', () => {
cy
.clock()
.tick(10, { log: false })
.then(function () {
expect(this.logs[0]).to.be.undefined
})
})
})
})
})
18 changes: 11 additions & 7 deletions packages/driver/src/cy/commands/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module.exports = function (Commands, Cypress, cy, state) {

const { tick } = clock

clock.tick = function (ms) {
clock.tick = function (ms, options = {}) {
if ((ms != null) && !_.isNumber(ms)) {
$errUtils.throwErrByPath('tick.invalid_argument', { args: { arg: JSON.stringify(ms) } })
}
Expand All @@ -106,10 +106,14 @@ module.exports = function (Commands, Cypress, cy, state) {
ms = 0
}

const theLog = log('tick', `${ms}ms`, false, {
'Now': clock.details().now + ms,
'Ticked': `${ms} milliseconds`,
})
let theLog

if (options.log !== false) {
theLog = log('tick', `${ms}ms`, false, {
'Now': clock.details().now + ms,
'Ticked': `${ms} milliseconds`,
})
}

if (theLog) {
theLog.snapshot('before', { next: 'after' })
Expand Down Expand Up @@ -151,12 +155,12 @@ module.exports = function (Commands, Cypress, cy, state) {
return clock
},

tick (subject, ms) {
tick (subject, ms, options = {}) {
if (!clock) {
$errUtils.throwErrByPath('tick.no_clock')
}

clock.tick(ms)
clock.tick(ms, options)

return clock
},
Expand Down

4 comments on commit 35be2ae

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 35be2ae Mar 20, 2021

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.

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.9.0/circle-develop-35be2aea2ad1611d4b09fbf3a172a2473ca952a3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 35be2ae Mar 20, 2021

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.9.0/appveyor-develop-35be2aea2ad1611d4b09fbf3a172a2473ca952a3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 35be2ae Mar 20, 2021

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.9.0/appveyor-develop-35be2aea2ad1611d4b09fbf3a172a2473ca952a3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 35be2ae Mar 20, 2021

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.

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.9.0/circle-develop-35be2aea2ad1611d4b09fbf3a172a2473ca952a3/cypress.tgz

Please sign in to comment.