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

tests: fix i18n-test bugs in Node 13 #10595

Merged
merged 2 commits into from
Apr 17, 2020
Merged

tests: fix i18n-test bugs in Node 13 #10595

merged 2 commits into from
Apr 17, 2020

Conversation

brendankenny
Copy link
Member

helps check off some of #10582

Two test issues here:

  1. Node 13 has a Intl.NumberFormat bug where a NaN that was stored in a property on an object will be formatted as -NaN, e.g. ({a: NaN}).a.toLocaleString() === '-NaN'. This also happens in V8 7.9/8.0 (~Chrome 79 and 80) but works correctly before and after these versions.

    Formatting NaNs isn't exactly important to our report, we added the test to exercise the corner cases and make sure they wouldn't cause a crash, so this PR adds a narrow workaround to the test that can be removed later. Try not to put NaNs in the report or they'll be negative for Node 13 users :)

  2. The thousands separator for Spanish was removed starting in Node 13, causing the swap-locale formatted-number test to fail. Looking for NaN bugs I ran across this crbug, where it turns out that "Linguist experts in CLDR require two digits before the group separator for Spanish" (so a number has to be ≥ 10000 before getting a separator) which was fixed in V8 by an ICU update at some point.

    Unfortunately we don't have any 5+ digit formatted number in sample_v2.json to get the separator back, so this just switches the test to swap the locale to de, which does have 1 as its minimumGroupingDigits.

@brendankenny brendankenny requested a review from a team as a code owner April 16, 2020 19:26
@brendankenny brendankenny requested review from connorjclark and removed request for a team April 16, 2020 19:26
@brendankenny brendankenny requested review from paulirish and removed request for connorjclark April 16, 2020 19:27
@brendankenny
Copy link
Member Author

R: @paulirish since he was also looking at these failures

// user-facing strings and it will eventually correct itself.
const formattedNaNStr = i18n.getFormatted(helloNaNStr, 'en-US');
expect(formattedNaNStr === 'Hello NaN World' || formattedNaNStr === 'Hello -NaN World')
.toBe(true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

originally I had this as a conditional

if (({a: NaN}).a.toLocaleString() === '-NaN') {
  expect(helloNaNStr).toBeDisplayString('Hello -NaN World');
} else {
  expect(helloNaNStr).toBeDisplayString('Hello NaN World');
}

but the conditional was always going to the else clause and then failing on the Hello NaN World assertion, so I gave up on figuring that out :) I assume some codegen thing.

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Linguist experts in CLDR require two digits before the group separator for Spanish"

i love this. ahahaah

lighthouse-core/test/lib/i18n/i18n-test.js Outdated Show resolved Hide resolved
@@ -11,27 +11,27 @@ const lhr = require('../../results/sample_v2.json');

/* eslint-env jest */
describe('swap-locale', () => {
it('can change golden LHR english strings into spanish', () => {
it('can change golden LHR english strings into german', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

image

Co-Authored-By: Paul Irish <paulirish@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants