Skip to content

Timezone dependent tests #79

@faridnsh

Description

@faridnsh

Summary

The hardcoded dates(2020-10-24) is in CEST timezone for me which is +2. Ideally the tests shouldn't be affected by timezone.

Steps to reproduce

Run npm test on a machine that 24 oct is not on GMT+1 timezone.

Expected results

Tests not failing when machine timezone changes.

Actual results

 FAIL  __tests__/queries/groupedAggregatesByDerivative.test.ts
  ● GroupedAggregatesByDerivative

    expect(received).toMatchSnapshot(hint)

    Snapshot name: `GroupedAggregatesByDerivative: result 1`

    - Snapshot  - 18
    + Received  + 18

      {
        "allMatchStats": {
          "byDay": [
            {
              "average": {
    -           "points": "225.5714285714285714",
    +           "points": "189.2307692307692308",
              },
              "keys": [
    -           "2020-10-24T00:00:00.000000+01:00",
    +           "2020-10-23T00:00:00.000000+02:00",
              ],
            },
            {
              "average": {
    -           "points": "176.8000000000000000",
    +           "points": "294.6153846153846154",
              },
              "keys": [
    -           "2020-10-25T00:00:00.000000+01:00",
    +           "2020-10-22T00:00:00.000000+02:00",
              ],
            },
            {
              "average": {
    -           "points": "294.6153846153846154",
    +           "points": "225.5714285714285714",
              },
              "keys": [
    -           "2020-10-22T00:00:00.000000+01:00",
    +           "2020-10-24T00:00:00.000000+02:00",
              ],
            },
            {
              "average": {
    -           "points": "189.2307692307692308",
    +           "points": "176.8000000000000000",
              },
              "keys": [
    -           "2020-10-23T00:00:00.000000+01:00",
    +           "2020-10-25T00:00:00.000000+02:00",
              ],
            },
          ],
          "byHour": [
            {
              "average": {
                "points": "185.6666666666666667",
              },
              "keys": [
    -           "2020-10-24T20:00:00.000000+01:00",
    +           "2020-10-24T21:00:00.000000+02:00",
              ],
            },
            {
              "average": {
                "points": "69.0000000000000000",
              },
              "keys": [
    -           "2020-10-24T18:00:00.000000+01:00",
    +           "2020-10-24T19:00:00.000000+02:00",
              ],
            },
            {
              "average": {
                "points": "310.2000000000000000",
              },
              "keys": [
    -           "2020-10-22T19:00:00.000000+01:00",
    +           "2020-10-22T20:00:00.000000+02:00",
              ],
            },
            {
              "average": {
                "points": "31.0000000000000000",
              },
              "keys": [
    -           "2020-10-25T18:00:00.000000+00:00",
    +           "2020-10-25T19:00:00.000000+01:00",
              ],
            },
            {
              "average": {
                "points": "163.7777777777777778",
              },
              "keys": [
    -           "2020-10-23T19:00:00.000000+01:00",
    +           "2020-10-23T20:00:00.000000+02:00",
              ],
            },
            {
              "average": {
                "points": "213.2500000000000000",
              },
              "keys": [
    -           "2020-10-25T19:00:00.000000+00:00",
    +           "2020-10-25T20:00:00.000000+01:00",
              ],
            },
            {
              "average": {
                "points": "293.0000000000000000",
              },
              "keys": [
    -           "2020-10-23T20:00:00.000000+01:00",
    +           "2020-10-23T21:00:00.000000+02:00",
              ],
            },
            {
              "average": {
                "points": "107.0000000000000000",
              },
              "keys": [
    -           "2020-10-23T18:00:00.000000+01:00",
    +           "2020-10-23T19:00:00.000000+02:00",
              ],
            },
            {
              "average": {
                "points": "242.6666666666666667",
              },
              "keys": [
    -           "2020-10-22T20:00:00.000000+01:00",
    +           "2020-10-22T21:00:00.000000+02:00",
              ],
            },
            {
              "average": {
                "points": "253.2000000000000000",
              },
              "keys": [
    -           "2020-10-24T19:00:00.000000+01:00",
    +           "2020-10-24T20:00:00.000000+02:00",
              ],
            },
          ],
        },
      }

      74 |       expect(errors).toMatchSnapshot("errors");
      75 |     }
    > 76 |     expect(data).toMatchSnapshot("result");
         |                  ^
      77 |     expect(queries).toMatchSnapshot("sql");
      78 |     // TODO: plan?
      79 |

      at Object.toMatchSnapshot (__tests__/helpers.ts:76:18)

 › 1 snapshot failed.
 PASS  __tests__/queries/loadsOfAggregates.test.ts
 PASS  __tests__/queries/focussedOrderAggregates.test.ts
 FAIL  __tests__/queries/averageGoalsOnDaysWithAveragePointsOver200.test.ts
  ● AverageGoalsOnDaysWithAveragePointsOver200

    expect(received).toMatchSnapshot(hint)

    Snapshot name: `AverageGoalsOnDaysWithAveragePointsOver200: result 1`

    - Snapshot  - 4
    + Received  + 4

      {
        "allMatchStats": {
          "byDay": [
            {
              "average": {
    -           "goals": "2.8571428571428571",
    +           "goals": "2.8461538461538462",
              },
              "keys": [
    -           "2020-10-24T00:00:00.000000+01:00",
    +           "2020-10-22T00:00:00.000000+02:00",
              ],
            },
            {
              "average": {
    -           "goals": "2.8461538461538462",
    +           "goals": "2.8571428571428571",
              },
              "keys": [
    -           "2020-10-22T00:00:00.000000+01:00",
    +           "2020-10-24T00:00:00.000000+02:00",
              ],
            },
          ],
        },
      }

      74 |       expect(errors).toMatchSnapshot("errors");
      75 |     }
    > 76 |     expect(data).toMatchSnapshot("result");
         |                  ^
      77 |     expect(queries).toMatchSnapshot("sql");
      78 |     // TODO: plan?
      79 |

      at Object.toMatchSnapshot (__tests__/helpers.ts:76:18)

 › 1 snapshot failed.
 PASS  __tests__/schema.test.ts
 PASS  __tests__/queries/averageDurationByYearOfRelease.test.ts
 PASS  __tests__/queries/filmAggregates.test.ts

Snapshot Summary
 › 2 snapshots failed from 2 test suites. Inspect your code changes or run `npm test -- -u` to update them.

Test Suites: 2 failed, 7 passed, 9 total
Tests:       2 failed, 7 passed, 9 total
Snapshots:   2 failed, 15 passed, 17 total
Time:        4.981 s, estimated 5 s
Ran all test suites.

Possible Solutions

I can think of two solutions:

  1. In helpers.ts set timezone upon connection
  2. In README.md mention testing database timezone must be set to specific timezone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions