From 263c02c8a02ee1c54118cbc7a28e54127ce4dbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Sun, 17 May 2026 18:22:59 +0200 Subject: [PATCH] Add test for image URLs in README 3rd party extension tables (#14731) --- sdk.d.ts | 8 ++++++- sdk.mjs | 8 +++++++ tests/docs.test.js | 59 +++++++++++++++++++++++++--------------------- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/sdk.d.ts b/sdk.d.ts index 1d0c08608..85723cf8d 100644 --- a/sdk.d.ts +++ b/sdk.d.ts @@ -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 */ diff --git a/sdk.mjs b/sdk.mjs index 23e94e81b..2c9f10a21 100644 --- a/sdk.mjs +++ b/sdk.mjs @@ -178,6 +178,11 @@ const parseModuleAuthorFromLine = (line) => { throw new Error(`Module URL improperly parsed from line: ${line}`); } + const moduleImageUrl = / { module: { name: moduleName, url: moduleUrl, + image: { + url: moduleImageUrl, + }, }, author: { name: authorName, diff --git a/tests/docs.test.js b/tests/docs.test.js index a32c9364e..fe7a1fa02 100644 --- a/tests/docs.test.js +++ b/tests/docs.test.js @@ -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}`} */ ( + `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.`, + ); + } + }); +}