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

[Bug]: React test formatFullDate fails as it is locale specific #2402

Closed
3 tasks done
phw opened this issue Jun 16, 2023 · 2 comments
Closed
3 tasks done

[Bug]: React test formatFullDate fails as it is locale specific #2402

phw opened this issue Jun 16, 2023 · 2 comments
Labels
bug frozen-due-to-age triage New bug reports that need to be evaluated

Comments

@phw
Copy link
Contributor

phw commented Jun 16, 2023

I confirm that:

  • I have searched the existing open AND closed issues to see if an issue already exists for the bug I've encountered
  • I'm using the latest version (your issue may have been fixed already)

Version

Latest git commit

Current Behavior

The test formatFullDate in src/utils/formatters.test.js is failing on locales other then English, as the date formatting is locale dependent. Below is the test failing with German locale:

> react-scripts test --watchAll=false

 FAIL  src/utils/formatters.test.js
  ● formatFullDate › format bytes

    expect(received).toEqual(expected) // deep equality

    Expected: "Jun 2011"
    Received: "Juni 2011"

      43 |   it('format bytes', () => {
      44 |     expect(formatFullDate('2011')).toEqual('2011')
    > 45 |     expect(formatFullDate('2011-06')).toEqual('Jun 2011')
         |                                       ^
      46 |     expect(formatFullDate('1985-01-01')).toEqual('Jan 1, 1985')
      47 |     expect(formatFullDate('199704')).toEqual('')
      48 |   })

      at Object.<anonymous> (src/utils/formatters.test.js:45:39)

Expected Behavior

Tests pass independent of locale. Probably locale should be set specifically for the test to English or C

Steps To Reproduce

LC_ALL=fr make pre-push

to fix failing tests if you are running a foreign locale:

LC_ALL=C make pre-push

Environment

- OS: Ubuntu 23.04

How Navidrome is installed?

Built from sources

Configuration

No response

Relevant log output

No response

Anything else?

No response

Code of Conduct

  • I agree to follow Navidrome's Code of Conduct
@phw phw added bug triage New bug reports that need to be evaluated labels Jun 16, 2023
@deluan
Copy link
Member

deluan commented Jun 16, 2023

Thanks for catching this. I added this piece of code to the tests, hoping it would avoid this:

  beforeAll(() => {
    const toLocaleString = Date.prototype.toLocaleString
    // eslint-disable-next-line no-extend-native
    Date.prototype.toLocaleString = function (locale = 'en-US', ...args) {
      return toLocaleString.call(this, locale, ...args)
    }
  })

but looks like it didn't. I'll take a look.

@deluan deluan closed this as completed in 36eda87 Jun 16, 2023
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug frozen-due-to-age triage New bug reports that need to be evaluated
Projects
None yet
Development

No branches or pull requests

2 participants