Exclude 'get' logo in load-simple-icons/fixes: logos: TypeError: Cannot read property '1' of null (#4488)
* Exclude 'get' key from simple icons * Improved assertion readability * A comment added in test
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
const simpleIcons = require('simple-icons')
|
||||
const originalSimpleIcons = require('simple-icons')
|
||||
const { svg2base64 } = require('./svg-helpers')
|
||||
|
||||
function loadSimpleIcons() {
|
||||
Object.keys(simpleIcons).forEach(key => {
|
||||
const simpleIcons = {}
|
||||
Object.keys(originalSimpleIcons).forEach(key => {
|
||||
const k = key.toLowerCase().replace(/ /g, '-')
|
||||
if (k !== key) {
|
||||
simpleIcons[k] = simpleIcons[key]
|
||||
delete simpleIcons[key]
|
||||
}
|
||||
simpleIcons[k] = originalSimpleIcons[key]
|
||||
simpleIcons[k].base64 = {
|
||||
default: svg2base64(
|
||||
simpleIcons[k].svg.replace('<svg', `<svg fill="#${simpleIcons[k].hex}"`)
|
||||
|
||||
29
lib/load-simple-icons.spec.js
Normal file
29
lib/load-simple-icons.spec.js
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict'
|
||||
|
||||
const { expect } = require('chai')
|
||||
const loadSimpleIcons = require('./load-simple-icons')
|
||||
|
||||
describe('loadSimpleIcons', function() {
|
||||
let simpleIcons
|
||||
before(function() {
|
||||
simpleIcons = loadSimpleIcons()
|
||||
})
|
||||
|
||||
it('prepares three color themes', function() {
|
||||
expect(simpleIcons['sentry'].base64).to.have.all.keys(
|
||||
'default',
|
||||
'light',
|
||||
'dark'
|
||||
)
|
||||
})
|
||||
|
||||
it('normalizes icon keys', function() {
|
||||
// original key in the simple-icons is 'Linux Foundation'
|
||||
expect(simpleIcons).to.include.key('linux-foundation')
|
||||
})
|
||||
|
||||
// https://github.com/badges/shields/issues/4016
|
||||
it('excludes "get" function provided by the simple-icons', function() {
|
||||
expect(simpleIcons).to.not.have.property('get')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user