From 6be07af824c0f0cc416417e1ae3ab6096e37fc74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Sun, 30 Jan 2022 23:09:44 +0100 Subject: [PATCH] Fix 3rd party extensions order, add test to avoid regression (#7111) * Fix 3rd party extensions order and add test to avoid regression * Prevent possible error in test * Apply suggestions from code review * Apply suggestion * Remove uneeded import --- README.md | 2 +- scripts/utils.js | 29 ++++++++++++++++- tests/readme-icons.test.js | 42 ------------------------- tests/readme.test.js | 64 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 44 deletions(-) delete mode 100644 tests/readme-icons.test.js create mode 100644 tests/readme.test.js diff --git a/README.md b/README.md index 4d1f7f18..06ded9d7 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,7 @@ echo file_get_contents('path/to/package/icons/simpleicons.svg'); | FlutterFlutter [Flutter package](https://pub.dev/packages/simple_icons) | [@jlnrrg](https://jlnrrg.github.io/) | | HexoHexo [Hexo plugin](https://github.com/nidbCN/hexo-simpleIcons) | [@nidbCN](https://github.com/nidbCN/) | | Home AssistantHome Assistant [Home Assistant plugin](https://github.com/vigonotion/hass-simpleicons) | [@vigonotion](https://github.com/vigonotion/) | +| JavaJava [Java library](https://github.com/silentsoft/simpleicons4j) | [@silentsoft](https://github.com/silentsoft) | | Jetpack ComposeJetpack Compose [Jetpack Compose library](https://github.com/DevSrSouza/compose-icons) | [@devsrsouza](https://github.com/devsrsouza/) | | KirbyKirby [Kirby plugin](https://github.com/runxel/kirby3-simpleicons) | [@runxel](https://github.com/runxel) | | LaravelLaravel [Laravel Package](https://github.com/ublabs/blade-simple-icons) | [@adrian-ub](https://github.com/adrian-ub) | @@ -157,7 +158,6 @@ echo file_get_contents('path/to/package/icons/simpleicons.svg'); | SvelteSvelte [Svelte package](https://github.com/icons-pack/svelte-simple-icons) | [@wootsbot](https://github.com/wootsbot) | | VueVue [Vue package](https://github.com/mainvest/vue-simple-icons) | [@noahlitvin](https://github.com/noahlitvin) | | WordpressWordpress [WordPress plugin](https://wordpress.org/plugins/simple-icons/) | [@tjtaylo](https://github.com/tjtaylo) | -| JavaJava [Java library](https://github.com/silentsoft/simpleicons4j) | [@silentsoft](https://github.com/silentsoft) | [slug]: ./slugs.md diff --git a/scripts/utils.js b/scripts/utils.js index f7256e6e..a38c863f 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -97,7 +97,7 @@ export const htmlFriendlyToTitle = (htmlFriendlyTitle) => * Get contents of _data/simple-icons.json. */ export const getIconsDataString = () => { - const __dirname = path.dirname(fileURLToPath(import.meta.url)); + const __dirname = getDirnameFromImportMeta(import.meta.url); const rootDir = path.resolve(__dirname, '..'); const iconDataPath = path.resolve(rootDir, '_data', 'simple-icons.json'); return fs.readFile(iconDataPath, 'utf8'); @@ -117,3 +117,30 @@ export const getIconsData = async () => { */ export const getDirnameFromImportMeta = (importMetaUrl) => path.dirname(fileURLToPath(importMetaUrl)); + +/** + * Get information about third party extensions. + */ +export const getThirdPartyExtensions = async () => { + const __dirname = getDirnameFromImportMeta(import.meta.url); + const readmePath = path.resolve(__dirname, '..', 'README.md'); + const readmeContent = await fs.readFile(readmePath, 'utf8'); + return readmeContent + .split('## Third-Party Extensions\n\n')[1] + .split('\n\n')[0] + .split('\n') + .slice(2) + .map((line) => { + const [module, author] = line.split(' | '); + return { + module: { + name: /\[(.+)\]/.exec(module)[1], + url: /\((.+)\)/.exec(module)[1], + }, + author: { + name: /\[(.+)\]/.exec(author)[1], + url: /\((.+)\)/.exec(author)[1], + }, + }; + }); +}; diff --git a/tests/readme-icons.test.js b/tests/readme-icons.test.js deleted file mode 100644 index 76e8d9ec..00000000 --- a/tests/readme-icons.test.js +++ /dev/null @@ -1,42 +0,0 @@ -import fs from 'node:fs'; -import path from 'node:path'; -import { fileURLToPath } from 'node:url'; -import { test } from 'mocha'; -import { strict as assert } from 'node:assert'; - -const __dirname = path.dirname(fileURLToPath(import.meta.url)); -const root = path.dirname(__dirname); -const blackIconsPath = path.join(root, 'icons'); -const whiteIconsPath = path.join(root, 'assets', 'readme'); -const whiteIconsFileNames = fs.readdirSync(whiteIconsPath); - -for (let whiteIconFileName of whiteIconsFileNames) { - const whiteIconPath = path.join(whiteIconsPath, whiteIconFileName); - const blackIconPath = path.join( - blackIconsPath, - whiteIconFileName.replace(/-white\.svg$/, '.svg'), - ); - const whiteIconRelPath = path.relative(root, whiteIconPath); - const blackIconRelPath = path.relative(root, blackIconPath); - - test(`'${whiteIconRelPath}' content must be equivalent to '${blackIconRelPath}' content`, () => { - assert.ok( - whiteIconFileName.endsWith('-white.svg'), - `README icon assets file name '${whiteIconFileName}'` + - " must ends with '-white.svg'.", - ); - - assert.ok( - fs.existsSync(blackIconPath), - `Corresponding icon '${blackIconRelPath}' for README asset '${whiteIconRelPath}'` + - ` not found in '${path.dirname(blackIconRelPath)}' directory.`, - ); - - const whiteIconContent = fs.readFileSync(whiteIconPath, 'utf8'); - const blackIconContent = fs.readFileSync(blackIconPath, 'utf8'); - assert.equal( - whiteIconContent, - blackIconContent.replace(' { + const blackIconsPath = path.join(root, 'icons'); + const whiteIconsPath = path.join(root, 'assets', 'readme'); + const whiteIconsFileNames = fs.readdirSync(whiteIconsPath); + + for (let whiteIconFileName of whiteIconsFileNames) { + const whiteIconPath = path.join(whiteIconsPath, whiteIconFileName); + const blackIconPath = path.join( + blackIconsPath, + whiteIconFileName.replace(/-white\.svg$/, '.svg'), + ); + const whiteIconRelPath = path.relative(root, whiteIconPath); + const blackIconRelPath = path.relative(root, blackIconPath); + + test(`'${whiteIconRelPath}' content must be equivalent to '${blackIconRelPath}' content`, () => { + assert.ok( + whiteIconFileName.endsWith('-white.svg'), + `README icon assets file name '${whiteIconFileName}'` + + " must ends with '-white.svg'.", + ); + + assert.ok( + fs.existsSync(blackIconPath), + `Corresponding icon '${blackIconRelPath}' for README asset '${whiteIconRelPath}'` + + ` not found in '${path.dirname(blackIconRelPath)}' directory.`, + ); + + const whiteIconContent = fs.readFileSync(whiteIconPath, 'utf8'); + const blackIconContent = fs.readFileSync(blackIconPath, 'utf8'); + assert.equal( + whiteIconContent, + blackIconContent.replace(' { + const thirdPartyExtensions = await getThirdPartyExtensions(); + assert.ok(thirdPartyExtensions.length > 0); + + const thirdPartyExtensionsNames = thirdPartyExtensions.map( + (ext) => ext.module.name, + ); + + const expectedOrder = thirdPartyExtensionsNames.slice().sort(); + assert.deepEqual( + thirdPartyExtensionsNames, + expectedOrder, + 'Wrong alphabetical order of third party extensions in README.', + ); +});