1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-12-26 01:13:41 +02:00
simple-icons/tests/test-icon.js
Álvaro Mondéjar 3ee620b9d6
Forbid the usage of non secure URLs (#7855)
* Forbid the usage of non secure URLs

* Document in CONTRIBUTING

* Add test to forbid HTTP URLs in documentation pages
2022-09-24 17:37:03 +02:00

71 lines
2.1 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import { strict as assert } from 'node:assert';
import { describe, it } from 'mocha';
import { URL_REGEX } from '../scripts/utils.js';
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);
assert.match(subject.source, URL_REGEX);
});
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, URL_REGEX);
}
} else {
assert.equal(subject.license, undefined);
}
});
it('has a valid svg value', () => {
const svgFileContents = fs.readFileSync(svgPath, 'utf8');
assert.equal(subject.svg, svgFileContents);
});
});
};