Files
shields/services/npm/npm-unpacked-size.tester.js
chris48s 151c70dd17 Add ability to format bytes as metric or IEC; affects [bundlejs bundlephobia ChromeWebStoreSize CratesSize DockerSize GithubRepoSize GithubCodeSize GithubSize NpmUnpackedSize SpigetDownloadSize steam VisualStudioAppCenterReleasesSize whatpulse] (#10547)
* add renderSizeBadge helper, use it everywhere

- switch from pretty-bytes to byte-size
- add renderSizeBadge() helper function
- match upstream conventions for metric/IEC units
- add new test helpers and use them in service tests

* unrelated: fix npm unpacked size query param schema

not strictly related to this PR
but I noticed it was broken

* chromewebstore: reformat size string, test against isIecFileSize
2024-12-01 19:53:26 +00:00

29 lines
1.0 KiB
JavaScript

import { isMetricFileSize } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
t.create('Latest unpacked size')
.get('/firereact.json')
.expectBadge({ label: 'unpacked size', message: isMetricFileSize })
t.create('Nonexistent unpacked size with version')
.get('/express/4.16.0.json')
.expectBadge({ label: 'unpacked size', message: 'unknown' })
t.create('Unpacked size with version')
.get('/firereact/0.7.0.json')
.expectBadge({ label: 'unpacked size', message: '147.2 kB' })
t.create('Unpacked size for scoped package')
.get('/@testing-library/react.json')
.expectBadge({ label: 'unpacked size', message: isMetricFileSize })
t.create('Unpacked size for scoped package with version')
.get('/@testing-library/react/14.2.1.json')
.expectBadge({ label: 'unpacked size', message: '5.4 MB' })
t.create('Nonexistent unpacked size for scoped package with version')
.get('/@cycle/rx-run/7.2.0.json')
.expectBadge({ label: 'unpacked size', message: 'unknown' })