import { test } from '@japa/runner' import { throttle } from '#lib/edge/index' test.group('edge / throttle', () => { test('passes everything on, at most the given rate after the first second', async ({ assert }) => { const pieces = Array.from({ length: 30 }, (_, i) => new Uint8Array(1000).fill(i)) const started = Date.now() const out: Uint8Array[] = [] // 30,000 bytes at 20,000 B/s: the first 20,000 at once, the rest over ~0.5 s. for await (const piece of throttle(pieces, 20_000)) out.push(piece) const seconds = (Date.now() - started) / 1000 assert.deepEqual(out, pieces) assert.isAtLeast(seconds, 0.45) assert.isBelow(seconds, 1.2) }) })