Refactor badge color functions (#2742)

- Replace the idea of color schemes with the idea of named colors (since none of our colorschemes have used `colorA`)
- Pass through the normalized color to `_shields_test` to harmonize with BaseService and simplify testing
    - Update service tests
- Move responsibility for color generation into the npm package
- Remove several color helper functions and their tests
- Update gh-badge public API to accept `color` and `labelColor`

This is a precursor to refactoring some of the logo code for #2473.
This commit is contained in:
Paul Melnikow
2019-01-15 16:43:33 -05:00
committed by GitHub
parent cab689706f
commit 4597d77015
81 changed files with 492 additions and 669 deletions

View File

@@ -3,7 +3,6 @@
const Joi = require('joi')
const ServiceTester = require('../service-tester')
const { isMetric } = require('../test-validators')
const { colorScheme: colorsB } = require('../test-helpers')
const t = new ServiceTester({
id: 'NpmDownloads',
@@ -18,7 +17,7 @@ t.create('total downloads of left-pad')
Joi.object().keys({
name: 'downloads',
value: isMetric,
colorB: colorsB.brightgreen,
color: 'brightgreen',
})
)
@@ -35,7 +34,7 @@ t.create('total downloads of package with zero downloads')
downloads: [{ downloads: 0, day: '2018-01-01' }],
})
)
.expectJSON({ name: 'downloads', value: '0', colorB: colorsB.red })
.expectJSON({ name: 'downloads', value: '0', color: 'red' })
t.create('exact total downloads value')
.get('/dt/exact-value.json')
@@ -57,7 +56,7 @@ t.create('total downloads when network is off')
.expectJSON({
name: 'downloads',
value: 'inaccessible',
colorB: colorsB.lightgray,
color: 'lightgray',
})
t.create('total downloads of unknown package')
@@ -65,5 +64,5 @@ t.create('total downloads of unknown package')
.expectJSON({
name: 'downloads',
value: 'package not found or too new',
colorB: colorsB.red,
color: 'red',
})

View File

@@ -1,7 +1,6 @@
'use strict'
const Joi = require('joi')
const { colorScheme: colorsB } = require('../test-helpers')
const t = (module.exports = require('../create-service-tester')())
@@ -15,19 +14,19 @@ t.create('gets the license of express from a custom registry')
t.create('public domain license')
.get('/redux-auth.json?style=_shields_test')
.expectJSON({ name: 'license', value: 'WTFPL', colorB: '#7cd958' })
.expectJSON({ name: 'license', value: 'WTFPL', color: '#7cd958' })
t.create('copyleft license')
.get('/trianglify.json?style=_shields_test')
.expectJSON({ name: 'license', value: 'GPL-3.0', colorB: colorsB.orange })
.expectJSON({ name: 'license', value: 'GPL-3.0', color: 'orange' })
t.create('permissive license')
.get('/express.json?style=_shields_test')
.expectJSON({ name: 'license', value: 'MIT', colorB: colorsB.green })
.expectJSON({ name: 'license', value: 'MIT', color: 'green' })
t.create('permissive license for scoped package')
.get('/@cycle%2Fcore.json?style=_shields_test')
.expectJSON({ name: 'license', value: 'MIT', colorB: colorsB.green })
.expectJSON({ name: 'license', value: 'MIT', color: 'green' })
t.create(
'permissive and copyleft licenses (SPDX license expression syntax version 2.0)'
@@ -36,7 +35,7 @@ t.create(
.expectJSON({
name: 'license',
value: '(MPL-2.0 OR MIT)',
colorB: colorsB.lightgrey,
color: 'lightgrey',
})
t.create('license for package without a license property')
@@ -49,7 +48,7 @@ t.create('license for package without a license property')
maintainers: [],
})
)
.expectJSON({ name: 'license', value: 'missing', colorB: colorsB.red })
.expectJSON({ name: 'license', value: 'missing', color: 'red' })
t.create('license for package with a license object')
.get('/package-license-object.json?style=_shields_test')
@@ -65,7 +64,7 @@ t.create('license for package with a license object')
maintainers: [],
})
)
.expectJSON({ name: 'license', value: 'MIT', colorB: colorsB.green })
.expectJSON({ name: 'license', value: 'MIT', color: 'green' })
t.create('license for package with a license array')
.get('/package-license-array.json?style=_shields_test')
@@ -81,7 +80,7 @@ t.create('license for package with a license array')
.expectJSON({
name: 'license',
value: 'MPL-2.0, MIT',
colorB: colorsB.green,
color: 'green',
})
t.create('license for unknown package')
@@ -89,16 +88,7 @@ t.create('license for unknown package')
.expectJSON({
name: 'license',
value: 'package not found',
colorB: colorsB.red,
})
t.create('license when network is off')
.get('/pakage-network-off.json?style=_shields_test')
.networkOff()
.expectJSON({
name: 'license',
value: 'inaccessible',
colorB: colorsB.lightgrey,
color: 'red',
})
// This tests error-handling functionality in NpmBase.