10

We use Cypress and cypress-image-snapshot for snapshot testing. Unfortunately we have issues with our colleagues based in another countries running the tests since they fail because of different timezones. In our date related components we pass strings in ISO 8601 format to set the date.

For our jest tests we use mocks (Components using Date objects produce different snapshots in different timezones) but not quite sure how to handle the situation in Cypress.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
pollx
  • 643
  • 9
  • 21
  • The Cypress [docs](https://docs.cypress.io/guides/tooling/visual-testing.html) specifically highlight `cy.clock`, have you looked into that? – jonrsharpe Nov 10 '19 at 16:47
  • 3
    `cy.clock()` is for speeding up JS timer functions like `setTimeout()`, nothing to do with timezones so you can ignore that approach. – Ackroydd Nov 13 '19 at 19:37
  • 1
    You should be able to manage timezone issues by structuring the test so that it only checks **relative** time values. Could you please post a simple example to illustrate the problem? – Ackroydd Nov 13 '19 at 19:38

1 Answers1

18

You can open browser with different TZ from server by adding specific timezone before open, in this way

"scripts": {
  "cypress:open": "TZ=America/New_York cypress open",
  "cypress:run": "TZ=America/New_York cypress run"
}
Juampi Caceres
  • 316
  • 3
  • 4