@@ -17,7 +17,10 @@ test.describe('badge API', () => {
1717 'license' : 'license' ,
1818 'size' : 'install size' ,
1919 'downloads' : 'downloads/mo' ,
20+ 'downloads-day' : 'downloads/day' ,
2021 'downloads-week' : 'downloads/wk' ,
22+ 'downloads-month' : 'downloads/mo' ,
23+ 'downloads-year' : 'downloads/yr' ,
2124 'vulnerabilities' : 'vulns' ,
2225 'dependencies' : 'dependencies' ,
2326 'updated' : 'updated' ,
@@ -26,8 +29,14 @@ test.describe('badge API', () => {
2629 'created' : 'created' ,
2730 'maintainers' : 'maintainers' ,
2831 'deprecated' : 'status' ,
32+ 'quality' : 'quality' ,
33+ 'popularity' : 'popularity' ,
34+ 'maintenance' : 'maintenance' ,
35+ 'score' : 'score' ,
2936 }
3037
38+ const percentageTypes = new Set ( [ 'quality' , 'popularity' , 'maintenance' , 'score' ] )
39+
3140 for ( const [ type , expectedLabel ] of Object . entries ( badgeMap ) ) {
3241 test . describe ( `${ type } badge` , ( ) => {
3342 test ( 'renders correct label' , async ( { page, baseURL } ) => {
@@ -64,9 +73,35 @@ test.describe('badge API', () => {
6473 expect ( body ) . toContain ( packageName )
6574 expect ( body ) . not . toContain ( expectedLabel )
6675 } )
76+
77+ if ( percentageTypes . has ( type ) ) {
78+ test ( 'contains percentage value' , async ( { page, baseURL } ) => {
79+ const url = toLocalUrl ( baseURL , `/api/registry/badge/${ type } /vue` )
80+ const { body } = await fetchBadge ( page , url )
81+
82+ expect ( body ) . toMatch ( / \d + % | u n k n o w n / )
83+ } )
84+ }
6785 } )
6886 }
6987
88+ test . describe ( 'specific scenarios' , ( ) => {
89+ test ( 'downloads-year handles large numbers' , async ( { page, baseURL } ) => {
90+ const url = toLocalUrl ( baseURL , '/api/registry/badge/downloads-year/lodash' )
91+ const { body } = await fetchBadge ( page , url )
92+
93+ expect ( body ) . toContain ( 'downloads/yr' )
94+ expect ( body ) . not . toContain ( 'NaN' )
95+ } )
96+
97+ test ( 'deprecated badge shows active for non-deprecated packages' , async ( { page, baseURL } ) => {
98+ const url = toLocalUrl ( baseURL , '/api/registry/badge/deprecated/vue' )
99+ const { body } = await fetchBadge ( page , url )
100+
101+ expect ( body ) . toContain ( 'active' )
102+ } )
103+ } )
104+
70105 test ( 'custom color parameter is applied to SVG' , async ( { page, baseURL } ) => {
71106 const customColor = 'ff69b4'
72107 const url = toLocalUrl ( baseURL , `/api/registry/badge/version/nuxt?color=${ customColor } ` )
0 commit comments