|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { |
| 3 | + formatBytes, |
| 4 | + formatDuration, |
| 5 | + pluralize, |
| 6 | + pluralizeToken, |
| 7 | + slugify, |
| 8 | +} from './formatting'; |
| 9 | + |
| 10 | +describe('slugify', () => { |
| 11 | + it.each([ |
| 12 | + ['Largest Contentful Paint', 'largest-contentful-paint'], |
| 13 | + ['cumulative-layout-shift', 'cumulative-layout-shift'], |
| 14 | + ['max-lines-200', 'max-lines-200'], |
| 15 | + ['rxjs/finnish', 'rxjs-finnish'], |
| 16 | + ['@typescript-eslint/no-explicit-any', 'typescript-eslint-no-explicit-any'], |
| 17 | + ['Code PushUp ', 'code-pushup'], |
| 18 | + ])('should transform "%s" to valid slug "%s"', (text, slug) => { |
| 19 | + expect(slugify(text)).toBe(slug); |
| 20 | + }); |
| 21 | +}); |
| 22 | + |
| 23 | +describe('pluralize', () => { |
| 24 | + it.each([ |
| 25 | + ['warning', 'warnings'], |
| 26 | + ['error', 'errors'], |
| 27 | + ['category', 'categories'], |
| 28 | + ['status', 'statuses'], |
| 29 | + ])('should pluralize "%s" as "%s"', (singular, plural) => { |
| 30 | + expect(pluralize(singular)).toBe(plural); |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +describe('formatBytes', () => { |
| 35 | + it.each([ |
| 36 | + [0, '0 B'], |
| 37 | + [1000, '1000 B'], |
| 38 | + [10000, '9.77 kB'], |
| 39 | + [10000000, '9.54 MB'], |
| 40 | + [10000000000, '9.31 GB'], |
| 41 | + [10000000000000, '9.09 TB'], |
| 42 | + [10000000000000000, '8.88 PB'], |
| 43 | + [10000000000000000000, '8.67 EB'], |
| 44 | + [10000000000000000000000, '8.47 ZB'], |
| 45 | + [10000000000000000000000000, '8.27 YB'], |
| 46 | + [10000000000000000000000, '8.47 ZB'], |
| 47 | + [10000000000000000000000, '8.47 ZB'], |
| 48 | + ])('should log file sizes correctly for %s`', (bytes, displayValue) => { |
| 49 | + expect(formatBytes(bytes)).toBe(displayValue); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should log file sizes correctly with correct decimal`', () => { |
| 53 | + expect(formatBytes(10000, 1)).toBe('9.8 kB'); |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
| 57 | +describe('pluralizeToken', () => { |
| 58 | + it.each([ |
| 59 | + [undefined, '0 files'], |
| 60 | + [-2, '-2 files'], |
| 61 | + [-1, '-1 file'], |
| 62 | + [0, '0 files'], |
| 63 | + [1, '1 file'], |
| 64 | + [2, '2 files'], |
| 65 | + ])('should log correct plural for %s`', (times, plural) => { |
| 66 | + expect(pluralizeToken('file', times)).toBe(plural); |
| 67 | + }); |
| 68 | +}); |
| 69 | + |
| 70 | +describe('formatDuration', () => { |
| 71 | + it.each([ |
| 72 | + [-1, '-1 ms'], |
| 73 | + [0, '0 ms'], |
| 74 | + [1, '1 ms'], |
| 75 | + [2, '2 ms'], |
| 76 | + [1200, '1.20 s'], |
| 77 | + ])('should log correct plural for %s`', (ms, displayValue) => { |
| 78 | + expect(formatDuration(ms)).toBe(displayValue); |
| 79 | + }); |
| 80 | +}); |
0 commit comments