summaryrefslogtreecommitdiffstats
path: root/tests/logger.test.ts
blob: e19f46625d2da2917815de01b3d1e2dbf3ce7497 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { expect, test } from 'bun:test';

// Re-implement the helper functions for testing (since they're private in the module)
function formatTransferStats(bytes: number, elapsedSeconds: number): string {
    const sizeMB = (bytes / (1024 * 1024)).toFixed(2);
    const speedMBps = (bytes / (1024 * 1024) / elapsedSeconds).toFixed(2);
    return `${sizeMB} MB (${speedMBps} MB/s)`;
}

test('formatTransferStats formats bytes correctly', () => {
    // 10 MB over 1 second
    expect(formatTransferStats(10 * 1024 * 1024, 1)).toBe('10.00 MB (10.00 MB/s)');

    // 5.5 MB over 2 seconds (2.75 MB/s)
    expect(formatTransferStats(5.5 * 1024 * 1024, 2)).toBe('5.50 MB (2.75 MB/s)');

    // 1 KB (0.00 MB)
    expect(formatTransferStats(1024, 1)).toBe('0.00 MB (0.00 MB/s)');
});

test('formatTransferStats handles zero elapsed time', () => {
    // Should handle gracefully (Infinity would be wrong)
    const bytes = 1024 * 1024; // 1 MB
    const result = formatTransferStats(bytes, 0);
    expect(result).toContain('1.00 MB');
});