-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bundlephobia] add badge for the npm package size (#1481)
* Added a shield for calculating npm bundle sizes * Fix linting errors * Fixed badges for bundlephobia * Remove un-required keywords * Simplified handler based on feedback * Use isFileSize for validation * Convert camel-cased error codes to space separated ones * Updated error format * Fixed error formatting * Renamed gzip to minzip * Fixes lint error * Remove test that times out * refactor tests to make it more readable * meaningless change * use trim
- Loading branch information
1 parent
cbb263b
commit 8ad176d
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
'use strict' | ||
|
||
const Joi = require('joi') | ||
const ServiceTester = require('./runner/service-tester') | ||
const { isFileSize } = require('./helpers/validators') | ||
|
||
const t = new ServiceTester({ | ||
id: 'bundlephobia', title: 'NPM package bundle size', | ||
}) | ||
|
||
module.exports = t | ||
|
||
const formats = { | ||
A: '/bundlephobia/:type/:package.:format', | ||
B: '/bundlephobia/:type/:package/:version.:format', | ||
C: '/bundlephobia/:type/@:scope/:package.:format', | ||
D: '/bundlephobia/:type/@:scope/:package/:version.:format', | ||
} | ||
|
||
const data = [ | ||
{ | ||
format: formats.A, | ||
get: '/min/preact.json', | ||
expect: { name: 'minified size', value: isFileSize }, | ||
}, | ||
{ | ||
format: formats.B, | ||
get: '/min/preact/8.0.0.json', | ||
expect: { name: 'minified size', value: '7.94 kB' }, | ||
}, | ||
{ | ||
format: formats.C, | ||
get: '/min/@cycle/core.json', | ||
expect: { name: 'minified size', value: isFileSize }, | ||
}, | ||
{ | ||
format: formats.D, | ||
get: '/min/@cycle/core/7.0.0.json', | ||
expect: { name: 'minified size', value: '3.51 kB' }, | ||
}, | ||
{ | ||
format: formats.A, | ||
get: '/minzip/preact.json', | ||
expect: { name: 'minzipped size', value: isFileSize }, | ||
}, | ||
{ | ||
format: formats.B, | ||
get: '/minzip/preact/8.0.0.json', | ||
expect: { name: 'minzipped size', value: '3.35 kB' }, | ||
}, | ||
{ | ||
format: formats.C, | ||
get: '/minzip/@cycle/core.json', | ||
expect: { name: 'minzipped size', value: isFileSize }, | ||
}, | ||
{ | ||
format: formats.D, | ||
get: '/minzip/@cycle/core/7.0.0.json', | ||
expect: { name: 'minzipped size', value: '1.23 kB' }, | ||
}, | ||
{ | ||
format: formats.A, | ||
get: '/min/some-no-exist.json', | ||
expect: { name: 'minified size', value: 'package not found error' }, | ||
}, | ||
{ | ||
format: formats.C, | ||
get: '/min/@some-no-exist/some-no-exist.json', | ||
expect: { name: 'minified size', value: 'package not found error' }, | ||
} | ||
] | ||
|
||
data.forEach( ({format, get, expect }) => { | ||
t.create(`Testing format '${format}' against '${get}'`) | ||
.get(get) | ||
.expectJSONTypes(Joi.object().keys(expect)) | ||
} | ||
) |