mirror of
https://github.com/Mibew/simple-icons.git
synced 2024-11-16 18:34:12 +03:00
84c0149bba
* Remove newlines * Remove newline to fix test * Enforce `lf` line endings * Remove trailing newline enforcement * Remove `replace` to ensure no trailing newlines * Revert "Enforce `lf` line endings" This reverts commit 05a13db8c33cc0dbe78318e00ff51b6412f58094.
69 lines
2.0 KiB
JavaScript
69 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');
|
|
assert.equal(subject.svg, svgFileContents);
|
|
});
|
|
});
|
|
};
|