import { test } from 'node:test'; import assert from 'node:assert/strict'; import { formatSpeed, formatEta } from './s3.logic.ts'; test('formatSpeed switches from KB/s to MB/s at 1 MiB/s', () => { assert.equal(formatSpeed(500 * 1024), '500 KB/s'); assert.equal(formatSpeed(2.4 * 1024 * 1024), '2.4 MB/s'); }); test('formatEta uses seconds under a minute, m+s above', () => { assert.equal(formatEta(45), '45s'); assert.equal(formatEta(125), '2m 5s'); assert.equal(formatEta(0.2), '1s'); // ceil rounds up }); test('formatEta rounds once, so the remainder cannot reach a minute', () => { // The previous spelling read 125 as "3m 5s", rounding the minutes up and // then adding the remainder it had already absorbed. Rounding to whole // seconds first is what stops both that and a "1m 60s" from 119.5. assert.equal(formatEta(119.5), '2m 0s'); assert.equal(formatEta(59.5), '1m 0s'); assert.equal(formatEta(3600), '60m 0s'); });