Compare commits

...
Author SHA1 Message Date
Vojtech NovakandClaude Fable 5.2 e31e63a5c2 [build-tools] Fix formatBytes for sizes of 102.4 GB and larger
The last branch divided by 1024 instead of by the GB multiplier, so
200 GB was formatted as "209715200 GB". Add table tests for the helper.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-10 09:08:57 +01:00
3 changed files with 27 additions and 2 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
'@expo/build-tools': patch
---
Fix sizes of 102.4 GB and larger being logged with a value about a million times too large.
@@ -1,7 +1,7 @@
import fs from 'fs-extra';
import { vol } from 'memfs';
import { findArtifacts } from '../artifacts';
import { findArtifacts, formatBytes } from '../artifacts';
jest.mock('fs');
@@ -157,3 +157,23 @@ describe(findArtifacts, () => {
expect(errMsg).toEqual('There is no such file or directory "/dir1/dir2/dir3/dir4/file".');
});
});
describe(formatBytes, () => {
const KB = 1024;
const MB = 1024 * KB;
const GB = 1024 * MB;
it.each([
[0, '0'],
[512, '512 B'],
[1.5 * KB, '1.5 KB'],
[500 * KB, '500 KB'],
[20 * MB, '20.0 MB'],
[500 * MB, '500 MB'],
[1.5 * GB, '1.5 GB'],
[102.4 * GB, '102 GB'],
[200 * GB, '200 GB'],
])('formats %d bytes as %s', (bytes, expected) => {
expect(formatBytes(bytes)).toBe(expected);
});
});
+1 -1
View File
@@ -204,5 +204,5 @@ export function formatBytes(bytes: number): string {
if (bytes < 102.4 * multiplier) {
return `${(bytes / multiplier).toFixed(1)} GB`;
}
return `${Math.floor(bytes / 1024)} GB`;
return `${Math.floor(bytes / multiplier)} GB`;
}