任务书承诺这些在分发前已存在。/traffic /logs 补进读白名单(在流式清单 里却不在读白名单里,仪表盘和请求页一开工就 403),PUT /providers/rules 补进写白名单(规则页的立刻更新)。web/stream.ts 把分块流缝成完整的行, 分块边界和行边界无关是它存在的全部理由;shared/format.ts 是连接页和 仪表盘共用的流量数字格式化。
31 lines
938 B
TypeScript
31 lines
938 B
TypeScript
import { describe, expect, it } from 'bun:test'
|
|
import { formatBytes } from './format.ts'
|
|
|
|
describe('流量数字', () => {
|
|
it('零和不满 1KB 的按字节显示,不带小数', () => {
|
|
expect(formatBytes(0)).toBe('0 B')
|
|
expect(formatBytes(512)).toBe('512 B')
|
|
expect(formatBytes(1023)).toBe('1023 B')
|
|
})
|
|
|
|
it('1024 的边界正好换档', () => {
|
|
expect(formatBytes(1024)).toBe('1 KB')
|
|
expect(formatBytes(1024 * 1024)).toBe('1 MB')
|
|
})
|
|
|
|
it('不满 100 保留一位小数,够 100 取整', () => {
|
|
expect(formatBytes(23.4 * 1024 * 1024)).toBe('23.4 MB')
|
|
expect(formatBytes(234.7 * 1024 * 1024)).toBe('235 MB')
|
|
})
|
|
|
|
it('超大数停在 TB 档', () => {
|
|
expect(formatBytes(5 * 1024 ** 4)).toBe('5 TB')
|
|
expect(formatBytes(5000 * 1024 ** 4)).toBe('5000 TB')
|
|
})
|
|
|
|
it('脏输入不炸', () => {
|
|
expect(formatBytes(-1)).toBe('0 B')
|
|
expect(formatBytes(Number.NaN)).toBe('0 B')
|
|
})
|
|
})
|