-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
core(i18n): throw on excess placeholder replacement values #9580
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,14 +44,19 @@ describe('i18n', () => { | |
|
||
describe('#replaceIcuMessageInstanceIds', () => { | ||
it('replaces the references in the LHR', () => { | ||
const templateID = 'lighthouse-core/test/lib/i18n/fake-file.js | daString'; | ||
const reference = templateID + ' # 0'; | ||
const lhr = {audits: {'fake-audit': {title: reference}}}; | ||
const fakeFile = path.join(__dirname, 'fake-file-number-2.js'); | ||
const UIStrings = {aString: 'different {x}!'}; | ||
const formatter = i18n.createMessageInstanceIdFn(fakeFile, UIStrings); | ||
|
||
const title = formatter(UIStrings.aString, {x: 1}); | ||
const lhr = {audits: {'fake-audit': {title}}}; | ||
|
||
const icuMessagePaths = i18n.replaceIcuMessageInstanceIds(lhr, 'en-US'); | ||
expect(lhr.audits['fake-audit'].title).toBe('use me!'); | ||
expect(lhr.audits['fake-audit'].title).toBe('different 1!'); | ||
|
||
const expectedPathId = 'lighthouse-core/test/lib/i18n/fake-file-number-2.js | aString'; | ||
expect(icuMessagePaths).toEqual({ | ||
[templateID]: [{path: 'audits[fake-audit].title', values: {x: 1}}]}); | ||
[expectedPathId]: [{path: 'audits[fake-audit].title', values: {x: 1}}]}); | ||
}); | ||
}); | ||
|
||
|
@@ -191,5 +196,15 @@ describe('i18n', () => { | |
// eslint-disable-next-line max-len | ||
.toThrow(`ICU Message "Hello {timeInMs, number, seconds} World" contains a numeric reference ("timeInMs") but provided value was not a number`); | ||
}); | ||
|
||
it('throws an error if a value is provided that has no placeholder in the message', () => { | ||
const helloStr = str_(UIStrings.helloTimeInMsWorld, { | ||
timeInMs: 55, | ||
sirNotAppearingInThisString: 66, | ||
}); | ||
expect(_ => i18n.getFormatted(helloStr, 'en-US')) | ||
// eslint-disable-next-line max-len | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apparently we've decided there's disagreement on this point so we should never use @exterkamp I'm gonna love this convo next week where I can learn how splitting is possibly better 😆 |
||
.toThrow(`Provided value "sirNotAppearingInThisString" does not match any placeholder in ICU message "Hello {timeInMs, number, seconds} World"`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dangers of singletons :) this test was implicitly relying on the test above having called
createMessageInstanceIdFn