1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-12-16 01:10:30 +02:00
simple-icons/tests/test-icon.js
Sachin Raja a930dc57ec
convert scripts to esm (#6946)
* convert scripts to esm

* fix tests

* fix tests

* fix lints

* syncFs to fsSync

* named export for fs

Co-authored-by: LitoMore <LitoMore@users.noreply.github.com>

* fsSync to { promises as fs }

* convert update-svgs-count to esm

* rename data to icons

* fix build script

* switch svglintrc file to mjs

* use node: protocol

* pluralize getIcons

Co-authored-by: LitoMore <LitoMore@users.noreply.github.com>
2021-12-25 06:22:56 -08:00

72 lines
1.9 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import { suite } from 'uvu';
import * as assert from 'uvu/assert';
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 test = suite(icon.title);
const svgPath = path.resolve(iconsDir, `${slug}.svg`);
test('has the correct "title"', () => {
assert.is(subject.title, icon.title);
});
test('has the correct "slug"', () => {
assert.is(subject.slug, slug);
});
test('has the correct "hex" value', () => {
assert.is(subject.hex, icon.hex);
});
test('has the correct "source"', () => {
assert.is(subject.source, icon.source);
});
test('has an "svg" value', () => {
assert.type(subject.svg, 'string');
});
test('has a valid "path" value', () => {
assert.match(subject.path, /^[MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]+$/g);
});
test(`has ${icon.guidelines ? 'the correct' : 'no'} "guidelines"`, () => {
if (icon.guidelines) {
assert.is(subject.guidelines, icon.guidelines);
} else {
assert.is(subject.guidelines, undefined);
}
});
test(`has ${icon.license ? 'the correct' : 'no'} "license"`, () => {
if (icon.license) {
assert.is(subject.license.type, icon.license.type);
if (icon.license.type === 'custom') {
assert.is(subject.license.url, icon.license.url);
} else {
assert.match(subject.license.url, /^https?:\/\/[^\s]+$/);
}
} else {
assert.is(subject.license, undefined);
}
});
test('has a valid svg value', () => {
const svgFileContents = fs
.readFileSync(svgPath, 'utf8')
.replace(/\r?\n/, '');
assert.is(subject.svg, svgFileContents);
});
test.run();
};