Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular): minimum threshold
Browse files Browse the repository at this point in the history
hrocha16 authored and Keen Yee Liau committed Feb 19, 2019

Verified

This commit was signed with the committer’s verified signature.
carloe Carlo Eugster
1 parent da2ab7e commit bb85edd
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ export function calculateBytes(
let value = Number(matches[1]);
switch (matches[2] && matches[2].toLowerCase()) {
case '%':
value = baselineBytes * value / 100 * factor;
value = baselineBytes * value / 100;
break;
case 'kb':
value *= 1024;
@@ -167,5 +167,9 @@ export function calculateBytes(
break;
}

return value + baselineBytes;
if (baselineBytes === 0) {
return value;
}

return baselineBytes + value * factor;
}
Original file line number Diff line number Diff line change
@@ -67,6 +67,10 @@ describe('bundle-calculator', () => {
expect(calculateBytes('25.0gB')).toBe(25 * 1024 * 1024 * 1024);
});

it ('converts a decimal with mb and baseline', () => {
expect(calculateBytes('3mb', '5mb', -1)).toBe(2 * 1024 * 1024);
});

it ('converts a percentage with baseline', () => {
expect(calculateBytes('20%', '1mb')).toBe(1024 * 1024 * 1.2);
expect(calculateBytes('20%', '1mb', -1)).toBe(1024 * 1024 * 0.8);

0 comments on commit bb85edd

Please sign in to comment.