Polaris-react: Failing tests due to timezone issue

Created on 28 Nov 2018  路  8Comments  路  Source: Shopify/polaris-react

Issue summary

Running tests for ResourceList's DateSelector component results in two failures:

image

I'm guessing this is due to timezones (I'm on Eastern European Time/UTC+2) as we've seen a similar issue with our own internal date picker recently for timezones that are ahead of UTC 馃槵

Expected behavior

DateSelector tests should pass in all timezones.

Actual behavior

DateSelector tests fail in UTC+2 timezone (and possibly other timezones that are ahead of UTC).

Steps to reproduce the problem

Run tests with system set to UTC+2 timezone.

Specifications

  • Are you using the React components? (Y/N): Y
  • Polaris version number: 3.1.1
  • Browser: N/A
  • Device: N/A
  • Operating System: N/A
馃悰Bug

Most helpful comment

@andrewpye not sure if it's of interest to you, but a Shopify Partner made an ember port of Polaris: https://github.com/smile-io/ember-polaris

All 8 comments

Thanks for raising this @andrewpye!

One way to solve this would be to set the timezone to UTC before any tests run, maybe something like this inside sewing-kit.config.ts?

import {join} from 'path';
import {ConfigurationCallback, Env, Plugins} from '@shopify/sewing-kit';

const tests = join(__dirname, 'tests');

process.env.TZ = 'UTC';
....

We have a library that can help with this: https://github.com/Shopify/quilt/tree/master/packages/jest-dom-mocks#clockmocknow-number--date-void

One way to solve this would be to set the timezone to UTC before any tests run

I might be misunderstanding, but I'm not sure this is the way to approach this - if it's a genuine test failure then fixing the timezone in test setup is hiding the issue rather than addressing it. The test should pass in _any_ timezone rather than setting to UTC before running tests (in fact adding tests that use multiple timezones might be helpful here).

Hi @andrewpye! Does the library that @lemonmade shared help?

@dpersing I'm honestly not sure, I haven't had a chance to look into this (I actually work with Ember.js and was making a port of ResourceList when I found the issue). From what I can tell though the mock library won't help, since it doesn't seem to allow setting a time zone. I think this is a legitimate issue though rather than a test setup issue.

@andrewpye not sure if it's of interest to you, but a Shopify Partner made an ember port of Polaris: https://github.com/smile-io/ember-polaris

@danrosenthal I'm actually one of the @smile-io guys behind ember-polaris, that's how I stumbled across this issue 馃槈Appreciate the heads-up though, and nice to know you guys are aware of us! 馃檶

Was this page helpful?
0 / 5 - 0 ratings