Add test for image URLs in README 3rd party extension tables (#14731)

This commit is contained in:
Álvaro Mondéjar Rubio
2026-05-18 00:22:59 +08:00
committed by GitHub
parent df96a6ea71
commit 263c02c8a0
3 changed files with 47 additions and 28 deletions
Vendored
+7 -1
View File
@@ -16,7 +16,7 @@ export type {IconData, DuplicateAlias, Aliases} from './types.d.ts';
* @see {@link https://github.com/simple-icons/simple-icons#third-party-extensions Third-Party Extensions}
*/
export type ThirdPartyExtension = {
module: ThirdPartyExtensionSubject;
module: ThirdPartyExtensionModule;
author: ThirdPartyExtensionSubject;
};
@@ -25,6 +25,12 @@ type ThirdPartyExtensionSubject = {
url: string;
};
type ThirdPartyExtensionModule = ThirdPartyExtensionSubject & {
image: {
url: string;
};
};
/* The next code is autogenerated from sdk.mjs */
/* eslint-disable */
+8
View File
@@ -178,6 +178,11 @@ const parseModuleAuthorFromLine = (line) => {
throw new Error(`Module URL improperly parsed from line: ${line}`);
}
const moduleImageUrl = /<img src="(.[^"]+)"/v.exec(module_)?.[1];
if (moduleImageUrl === undefined) {
throw new Error(`Module image URL improperly parsed from line: ${line}`);
}
const authorName = /\[(.+)\]/v.exec(author)?.[1];
if (authorName === undefined) {
throw new Error(`Author improperly parsed from line: ${line}`);
@@ -192,6 +197,9 @@ const parseModuleAuthorFromLine = (line) => {
module: {
name: moduleName,
url: moduleUrl,
image: {
url: moduleImageUrl,
},
},
author: {
name: authorName,
+32 -27
View File
@@ -7,34 +7,39 @@ 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);
for (const extensionType of /** @type {const} */ ([
'extensions',
'libraries',
])) {
const testSubject = `README third-party ${extensionType}`;
const thirdPartyExtensionsNames = thirdPartyExtensions.map(
(extension) => extension.module.name,
);
const key =
/** @type {`getThirdParty${Capitalize<typeof extensionType>}`} */ (
`getThirdParty${extensionType[0].toUpperCase()}${extensionType.slice(1)}`
);
const getters = {getThirdPartyExtensions, getThirdPartyLibraries};
// eslint-disable-next-line no-await-in-loop
const extensions = await getters[key]();
const expectedOrder = thirdPartyExtensionsNames.toSorted();
assert.deepEqual(
thirdPartyExtensionsNames,
expectedOrder,
'Wrong alphabetical order of third-party extensions in README.',
);
});
test(`${testSubject} can be parsed`, () => {
assert.ok(extensions.length > 0);
});
test('README third-party libraries must be alphabetically sorted', async () => {
const thirdPartyLibraries = await getThirdPartyLibraries();
assert.ok(thirdPartyLibraries.length > 0);
test(`${testSubject} must be alphabetically sorted`, () => {
const names = extensions.map((item) => item.module.name);
assert.deepEqual(
names,
names.toSorted(),
`Wrong alphabetical order of third-party ${extensionType} in README.`,
);
});
const thirdPartyLibrariesNames = thirdPartyLibraries.map(
(library) => library.module.name,
);
const expectedOrder = thirdPartyLibrariesNames.toSorted();
assert.deepEqual(
thirdPartyLibrariesNames,
expectedOrder,
'Wrong alphabetical order of third-party libraries in README.',
);
});
test(`${testSubject} images must be consumed from the Simple Icons CDN`, () => {
for (const extension of extensions) {
assert.ok(
extension.module.image.url.startsWith('https://cdn.simpleicons.org/'),
`Wrong image URL for third-party ${extensionType.slice(0, -1)} ${extension.module.name} in README.`,
);
}
});
}