Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Fix failing test due to timezone + hardcoded fixture #107

Closed
wants to merge 8 commits into from

Conversation

DrewML
Copy link
Contributor

@DrewML DrewML commented Jan 30, 2020

Description

Hey Friends!

I'm from the @magento side of the house, working on some integrations with Adobe I/O.

I wanted to work against the latest aio-cli in master regularly to try and help catch any bugs prior to releases.

When cloning + running tests locally, I currently get one test failure from discover.test.js:

 FAIL  test/commands/discover.test.js
  ● name sort-field, ascending

    expect(received).toMatch(expected)

    Expected substring: "Name Version   Description Published·······
    bar  1.0.1     some bar    January 2, 1970·
    foo  1.0.0     some foo    January 1, 1970·
    "
    Received string:    "Name Version   Description Published·········
    bar  1.0.1     some bar    January 1, 1970···
    foo  1.0.0     some foo    December 31, 1969·
    "

      58 |     return command.run()
      59 |       .then(() => {
    > 60 |         expect(stdout.output).toMatch(
         |                               ^
      61 |           // TODO: add .toMatchFixture
      62 |           // eslint-disable-next-line indent
      63 | `Name Version   Description Published       

      at toMatch (test/commands/discover.test.js:60:31)

It looks like we're not setting an explicit timezone in our call to Date.prototype.toLocaleDateString, so it's defaulting to the local timezone.

I marked this as a breaking change but that's debatable. This fixes unit tests, but it means that dates spit to stdout from the discover command won't be localized.

Some alternatives I considered:

  • Do a process.env.NODE_ENV === 'test' check, and use UTC only in tests
  • Assert on substrings in the result from stdout, to avoid asserting on the date string

Let me know if you'd prefer one of these options instead.

Related Issue

Motivation and Context

Fix tests for users in other timezones

How Has This Been Tested?

npm test locally

Screenshots (if appropriate):

Before
image

After
image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Jan 30, 2020

Codecov Report

Merging #107 into master will not change coverage by %.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #107   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           69        69           
  Branches        10        10           
=========================================
  Hits            69        69           
Impacted Files Coverage Δ
src/commands/discover.js 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2a73ca7...bf80115. Read the comment docs.

@shazron
Copy link
Member

shazron commented Feb 3, 2020

Hi Drew! Thanks for the PR.
I think a localized date output is important. Therefore I'd prefer the "Assert on substrings in the result from stdout, to avoid asserting on the date string" method to avoid any potential magic branching code in the command itself (even though it would be a known Jest thing via the env var)

@DrewML
Copy link
Contributor Author

DrewML commented Feb 3, 2020

@shazron cool 👍 - sounds like the right choice to me. Will get an update pushed in a little while.

@DrewML DrewML closed this Feb 3, 2020
@DrewML DrewML reopened this Feb 3, 2020
@DrewML
Copy link
Contributor Author

DrewML commented Feb 3, 2020

(wrong button 🤦‍♂)

@shazron shazron changed the title Fix failing test due to timezone + hardcoded fixture WIP - Fix failing test due to timezone + hardcoded fixture Feb 15, 2020
@purplecabbage purplecabbage mentioned this pull request Mar 18, 2020
10 tasks
@purplecabbage
Copy link
Member

Thanks @DrewML
I resolved this issue by only testing the actual order of the results instead of string comparing expected date values.

@DrewML
Copy link
Contributor Author

DrewML commented Mar 20, 2020

Hey thanks for finishing this up @purplecabbage - have been playing catch up on some other things.

@DrewML DrewML deleted the timezone-test-failure branch March 20, 2020 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants