Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): minimum threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
hrocha16 authored and kyliau committed Feb 19, 2019
1 parent da2ab7e commit bb85edd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Expand Up @@ -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;
Expand All @@ -167,5 +167,9 @@ export function calculateBytes(
break;
}

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

return baselineBytes + value * factor;
}
Expand Up @@ -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);
Expand Down

0 comments on commit bb85edd

Please sign in to comment.