Convert simple-icons manual backup from submodule to tracked files
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// @ts-check
|
||||
/**
|
||||
* @file Tests for the documentation.
|
||||
*/
|
||||
|
||||
import {strict as assert} from 'node:assert';
|
||||
import {test} from 'mocha';
|
||||
import {getThirdPartyExtensions, getThirdPartyLibraries} from '../sdk.mjs';
|
||||
|
||||
test('README third party extensions must be alphabetically sorted', async () => {
|
||||
const thirdPartyExtensions = await getThirdPartyExtensions();
|
||||
assert.ok(thirdPartyExtensions.length > 0);
|
||||
|
||||
const thirdPartyExtensionsNames = thirdPartyExtensions.map(
|
||||
(extension) => extension.module.name,
|
||||
);
|
||||
|
||||
const expectedOrder = [...thirdPartyExtensionsNames].sort();
|
||||
assert.deepEqual(
|
||||
thirdPartyExtensionsNames,
|
||||
expectedOrder,
|
||||
'Wrong alphabetical order of third party extensions in README.',
|
||||
);
|
||||
});
|
||||
|
||||
test('README third party libraries must be alphabetically sorted', async () => {
|
||||
const thirdPartyLibraries = await getThirdPartyLibraries();
|
||||
assert.ok(thirdPartyLibraries.length > 0);
|
||||
|
||||
const thirdPartyLibrariesNames = thirdPartyLibraries.map(
|
||||
(library) => library.module.name,
|
||||
);
|
||||
|
||||
const expectedOrder = [...thirdPartyLibrariesNames].sort();
|
||||
assert.deepEqual(
|
||||
thirdPartyLibrariesNames,
|
||||
expectedOrder,
|
||||
'Wrong alphabetical order of third party libraries in README.',
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
// @ts-check
|
||||
/**
|
||||
* @file Tests for the index file of npm package.
|
||||
*/
|
||||
|
||||
// The index.mjs file is generated on build before running tests
|
||||
// @ts-ignore
|
||||
import * as rawSimpleIcons from '../index.mjs';
|
||||
import {getIconSlug, getIconsData, slugToVariableName} from '../sdk.mjs';
|
||||
import {testIcon} from './test-icon.js';
|
||||
|
||||
/** @type {{ [key: string]: import('../types.d.ts').SimpleIcon }} */
|
||||
const simpleIcons = rawSimpleIcons;
|
||||
|
||||
for (const iconData of await getIconsData()) {
|
||||
const slug = getIconSlug(iconData);
|
||||
const variableName = slugToVariableName(slug);
|
||||
const subject = simpleIcons[variableName];
|
||||
|
||||
testIcon(iconData, subject, slug);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// @ts-check
|
||||
/**
|
||||
* @file Custom mocha reporter.
|
||||
*
|
||||
* Serves to clear the console after the test run is finished.
|
||||
* See {@link https://github.com/mochajs/mocha/issues/2312}.
|
||||
*/
|
||||
|
||||
const {reporters, Runner} = require('mocha');
|
||||
|
||||
const {EVENT_RUN_END} = Runner.constants;
|
||||
|
||||
class EvenMoreMin extends reporters.Base {
|
||||
/**
|
||||
* Construct a new `EvenMoreMin` reporter.
|
||||
* @param {import('mocha').Runner} runner Mocha test runner.
|
||||
*/
|
||||
constructor(runner) {
|
||||
super(runner);
|
||||
runner.once(EVENT_RUN_END, () => this.epilogue());
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EvenMoreMin;
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// @ts-check
|
||||
/**
|
||||
* @file Icon tester.
|
||||
*/
|
||||
|
||||
import {strict as assert} from 'node:assert';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {describe, it} from 'mocha';
|
||||
import {SVG_PATH_REGEX} from '../sdk.mjs';
|
||||
|
||||
const iconsDirectory = path.resolve(import.meta.dirname, '..', 'icons');
|
||||
|
||||
/**
|
||||
* Checks if icon data matches a subject icon.
|
||||
* @param {import('../types.d.ts').IconData} icon Icon data.
|
||||
* @param {import('../types.d.ts').SimpleIcon} subject
|
||||
* Icon object to check against icon data.
|
||||
* @param {string} slug Icon data slug.
|
||||
*/
|
||||
export const testIcon = (icon, subject, slug) => {
|
||||
const svgPath = path.resolve(iconsDirectory, `${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, SVG_PATH_REGEX);
|
||||
});
|
||||
|
||||
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') {
|
||||
const {license} = icon;
|
||||
const license_ = /** @type {import('../types.js').CustomLicense} */ (
|
||||
license
|
||||
);
|
||||
assert.equal(subject.license.url, license_.url);
|
||||
}
|
||||
} else {
|
||||
assert.equal(subject.license, undefined);
|
||||
}
|
||||
});
|
||||
|
||||
it('has a valid svg value', async () => {
|
||||
const svgFileContents = await fs.readFile(svgPath, 'utf8');
|
||||
assert.equal(subject.svg, svgFileContents);
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user