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:
Marcin Mielnicki
2020-01-05 21:30:57 +01:00
committed by GitHub
parent 7806b71746
commit 88e2cac0f8
2 changed files with 33 additions and 6 deletions

View File

@@ -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}"`)

View 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')
})
})