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

core(budget): throw error on duplicate budget types #8915

Merged
merged 2 commits into from
May 16, 2019

Conversation

brendankenny
Copy link
Member

something missed in #8727

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.

change itself LGTM!

} else if (resourceCounts !== undefined) {
throw new Error(`Invalid resourceCounts entry in budget at index ${index}`);
}

if (isArrayOfUnknownObjects(timings)) {
budget.timings = timings.map(Budget.validateTimingBudget);
Budget.assertNoDuplicateStrings(budget.timings.map(r => r.metric),
`budget[${index}].timings`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

should these read budgets[${index}] since that's the property name?

Copy link
Member Author

Choose a reason for hiding this comment

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

should these read budgets[${index}] since that's the property name?

yeah, good call

it('throws when a duplicate resourceType is specified in resourceCounts', () => {
budget[0].resourceCounts.push({resourceType: 'third-party', budget: 100});
assert.throws(_ => Budget.initializeBudget(budget),
/budget\[0\]\.resourceCounts has duplicate entry of type 'third-party'/);
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe consider expect().toThrow('the message') to avoid regex escape noise when we're doing exact string matching?

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe consider expect().toThrow('the message') to avoid regex escape noise when we're doing exact string matching?

yeah, this whole file should probably switch over...

* @param {Array<string>} arr
* @param {string} arrayName
*/
static assertNoDuplicateStrings(arr, arrayName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

arr feels a bit of an unnecessary abbreviation 😛

Copy link
Member Author

Choose a reason for hiding this comment

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

arr feels a bit of an unnecessary abbreviation 😛

very fair :)

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.

2 participants