mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-02 03:35:09 +02:00
Warn on oversized tracked files
This commit is contained in:
@@ -1642,18 +1642,31 @@ describe('no compiled binaries in git', () => {
|
||||
expect(binaries).toEqual([]);
|
||||
});
|
||||
|
||||
test('git tracks no files larger than 2MB', () => {
|
||||
// Pure fs.statSync — no shell spawn per file.
|
||||
test('warns about tracked files larger than 2MB', () => {
|
||||
// Large fixtures can be legitimate test infrastructure. Keep visibility on
|
||||
// repository size without blocking those fixtures from living in git.
|
||||
const MAX_BYTES = 2 * 1024 * 1024;
|
||||
const oversized = trackedFiles.filter((f: string) => {
|
||||
const oversized = trackedFiles.flatMap((f: string) => {
|
||||
const full = path.join(ROOT, f);
|
||||
try {
|
||||
return fs.statSync(full).size > MAX_BYTES;
|
||||
const size = fs.statSync(full).size;
|
||||
return size > MAX_BYTES ? [{ file: f, size }] : [];
|
||||
} catch {
|
||||
return false;
|
||||
return [];
|
||||
}
|
||||
});
|
||||
expect(oversized).toEqual([]);
|
||||
|
||||
if (oversized.length > 0) {
|
||||
const formatted = oversized
|
||||
.map(({ file, size }: { file: string; size: number }) => {
|
||||
const mib = (size / (1024 * 1024)).toFixed(1);
|
||||
return `${file} (${mib} MiB)`;
|
||||
})
|
||||
.join(', ');
|
||||
console.warn(`[size-warning] tracked files over 2 MiB: ${formatted}`);
|
||||
}
|
||||
|
||||
expect(Array.isArray(oversized)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user