[go: nahoru, domu]

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(i18n): no ICU value given to preprocess #9384

Merged
merged 4 commits into from
Jul 17, 2019
Merged

Conversation

exterkamp
Copy link
Member

Summary
Add test for a missing ICU replacement value when gettingFormatted. Removed early exit from _preprocessMessageValues and added a default so that when sending no replacement object the function will still fire.

fixes: #9383

Copy link
Collaborator
@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

test change looks great!

@@ -127,9 +127,7 @@ function lookupLocale(locale) {
* @param {string} icuMessage
* @param {Record<string, *>} [values]
*/
function _preprocessMessageValues(icuMessage, values) {
if (!values) return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

feels like this change should be accompanied by a test too if we want to change it here :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we should change the typedef below (https://github.com/GoogleChrome/lighthouse/pull/9384/files#diff-4f100f14d281ddfaff2dc4466fc78054R167) to Record<string, any>?

I guess I'm just not sure why

so that when sending no replacement object the function will still fire.

is desirable.

Like why not just if (!values) return {} if we want to convert away from undefined

Copy link
Member

Choose a reason for hiding this comment

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

I guess I'm just not sure why

so that when sending no replacement object the function will still fire.

is desirable.

Like why not just if (!values) return {} if we want to convert away from undefined

I may be misinterpreting your question, but this came up when adding the test. _preprocessMessageValues does the "all ICU replacements in the string have a value provided" check, which works fine if there are multiple replacements to be done and one value (or more) is missing. However if the values object is forgotten completely, this line skips the check, even if the string has replacements that will need values.

It still ends up throwing, just in intl-messageformat, so if we are going to do a check here it made sense to do it for all strings that need replacements (instead of all strings that have values passed in with them).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, oh, oh, I misread the parsed.elements.forEach line to be Object.values(values).forEach, my bad!

yes, yes this makes perfect sense!

Still would love a test for forgetting the values completely, but I gotcha now! 👍 :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! I added a new test, and made the error message a bit more helpful.

Copy link
Member
@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM

agree with @patrickhulce that a test for a missing value and a test with the values object missing altogether would be good

Co-Authored-By: Brendan Kenny <bckenny@gmail.com>
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

Copy link
Collaborator
@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

LGTM!

@exterkamp
Copy link
Member Author
exterkamp commented Jul 17, 2019

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

Googlers: Go here for more info.

Yo @googlebot , I can't add cla: yes whats up?

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.

Add test to _preprocessMessageValues
4 participants