1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-11-16 00:59:07 +02:00
simple-icons/tests/test-icon.js
Sachin Raja d49492f1ef
switch from uvu to mocha (#7071)
* switch from uvu to mocha

* remove unused import

* custom min reporter

* use constants
2022-01-19 18:23:32 +01:00

71 lines
2.0 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import { strict as assert } from 'node:assert';
import { describe, it } from 'mocha';
const iconsDir = path.resolve(process.cwd(), 'icons');
/**
* Checks if icon data matches a subject icon.
* @param {import('..').SimpleIcon} icon Icon data
* @param {import('..').SimpleIcon} subject Icon to check against icon data
* @param {String} slug Icon data slug
*/
export const testIcon = (icon, subject, slug) => {
const svgPath = path.resolve(iconsDir, `${slug}.svg`);
describe(icon.title, () => {
it('has the correct "title"', () => {
assert.equal(subject.title, icon.title);
});
it('has the correct "slug"', () => {
assert.equal(subject.slug, slug);
});
it('has the correct "hex" value', () => {
assert.equal(subject.hex, icon.hex);
});
it('has the correct "source"', () => {
assert.equal(subject.source, icon.source);
});
it('has an "svg" value', () => {
assert.equal(typeof subject.svg, 'string');
});
it('has a valid "path" value', () => {
assert.match(subject.path, /^[MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]+$/g);
});
it(`has ${icon.guidelines ? 'the correct' : 'no'} "guidelines"`, () => {
if (icon.guidelines) {
assert.equal(subject.guidelines, icon.guidelines);
} else {
assert.equal(subject.guidelines, undefined);
}
});
it(`has ${icon.license ? 'the correct' : 'no'} "license"`, () => {
if (icon.license) {
assert.equal(subject.license.type, icon.license.type);
if (icon.license.type === 'custom') {
assert.equal(subject.license.url, icon.license.url);
} else {
assert.match(subject.license.url, /^https?:\/\/[^\s]+$/);
}
} else {
assert.equal(subject.license, undefined);
}
});
it('has a valid svg value', () => {
const svgFileContents = fs
.readFileSync(svgPath, 'utf8')
.replace(/\r?\n/, '');
assert.equal(subject.svg, svgFileContents);
});
});
};