Skip to content

Commit

Permalink
Allow handle() to return a numeric message (#2332)
Browse files Browse the repository at this point in the history
This regression from #2284 was causing `{ message: 22 }` to render as `’n/a’`, as in this test run: https://circleci.com/gh/badges/shields/23680
  • Loading branch information
paulmelnikow committed Nov 17, 2018
1 parent 065dd57 commit 547380f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion services/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const { staticBadgeUrl } = require('../lib/make-badge-url')
const trace = require('./trace')

function coalesce(...candidates) {
return candidates.find(c => typeof c === 'string')
return candidates.find(c => c !== undefined)
}

class BaseService {
Expand Down
15 changes: 15 additions & 0 deletions services/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,21 @@ describe('BaseService', function() {
expect(badgeData.text).to.deep.equal(['cat', '10k'])
})

it('preserves an empty label', function() {
const badgeData = DummyService._makeBadgeData(
{},
{ label: '', message: '10k' }
)
expect(badgeData.text).to.deep.equal(['', '10k'])
})

it('applies a numeric service message', function() {
// While a number of badges use this, in the long run we may want
// `render()` to always return a string.
const badgeData = DummyService._makeBadgeData({}, { message: 10 })
expect(badgeData.text).to.deep.equal(['cat', 10])
})

it('applies the service color', function() {
const badgeData = DummyService._makeBadgeData({}, { color: 'red' })
expect(badgeData.colorscheme).to.equal('red')
Expand Down

0 comments on commit 547380f

Please sign in to comment.