-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.test.ts
More file actions
36 lines (29 loc) · 1.11 KB
/
server.test.ts
File metadata and controls
36 lines (29 loc) · 1.11 KB
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
27
28
29
30
31
32
33
34
35
36
import { expect, test } from 'bun:test';
import { formatBytes, parseRsyncProgress } from './server';
import { existsSync } from 'fs';
import { homedir } from 'os';
test('formatBytes: zero returns dash', () => {
expect(formatBytes(0)).toBe('—');
});
test('formatBytes: kilobytes', () => {
expect(formatBytes(1024)).toBe('1.0 KB');
});
test('formatBytes: gigabytes', () => {
expect(formatBytes(1073741824)).toBe('1.0 GB');
});
test('parseRsyncProgress: valid progress line', () => {
const line = ' 1,234,567 45% 12.34MB/s 0:00:23';
expect(parseRsyncProgress(line)).toEqual({ percent: 45, speed: '12.34MB/s', eta: '0:00:23' });
});
test('parseRsyncProgress: non-progress line returns null', () => {
expect(parseRsyncProgress('sending incremental file list')).toBeNull();
});
test('parseRsyncProgress: kilobytes speed', () => {
const line = ' 512 12% 512.00kB/s 0:00:05';
const result = parseRsyncProgress(line);
expect(result?.percent).toBe(12);
expect(result?.speed).toBe('512.00kB/s');
});
test('Desktop directory exists', () => {
expect(existsSync(homedir() + '/Desktop')).toBe(true);
});