|
| 1 | +const t = require('tap') |
| 2 | +const formatBytes = require('../../../lib/utils/format-bytes.js') |
| 3 | + |
| 4 | +t.test('formatBytes', (t) => { |
| 5 | + t.equal(formatBytes(0), '0 B', '0 bytes') |
| 6 | + t.equal(formatBytes(1), '1 B', '1 byte') |
| 7 | + t.equal(formatBytes(10), '10 B', '10 bytes') |
| 8 | + t.equal(formatBytes(999), '999 B', '999 bytes') |
| 9 | + t.equal(formatBytes(1000), '1.0 kB', '1000 bytes') |
| 10 | + t.equal(formatBytes(1001), '1.0 kB', '1001 bytes') |
| 11 | + t.equal(formatBytes(1500), '1.5 kB', '1500 bytes') |
| 12 | + |
| 13 | + // Edge cases around rounding that currently fail |
| 14 | + t.equal(formatBytes(999999), '1.0 MB', '999999 bytes -> 1.0 MB') |
| 15 | + t.equal(formatBytes(1000000), '1.0 MB', '1000000 bytes -> 1.0 MB') |
| 16 | + |
| 17 | + t.equal(formatBytes(999999999), '1.0 GB', '999999999 bytes -> 1.0 GB') |
| 18 | + t.equal(formatBytes(1000000000), '1.0 GB', '1000000000 bytes -> 1.0 GB') |
| 19 | + |
| 20 | + // Checking formatting without space |
| 21 | + t.equal(formatBytes(999, false), '999B', '999B no space') |
| 22 | + t.equal(formatBytes(1000, false), '1.0kB', '1.0kB no space') |
| 23 | + |
| 24 | + t.end() |
| 25 | +}) |
0 commit comments