From 8f4e65ce288f096b01e382481739b6ce76a53ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Sat, 30 Apr 2022 09:04:46 -0500 Subject: [PATCH] Allow to use the function `getThirdPartyExtensions` at other locations (#7361) --- scripts/utils.js | 11 +++-------- tests/readme.test.js | 3 ++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/scripts/utils.js b/scripts/utils.js index 1193310af..194dc2eca 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -128,14 +128,10 @@ export const normalizeNewlines = (text) => { /** * Get information about third party extensions. + * @param {String} readmePath Path to the README file */ -export const getThirdPartyExtensions = async () => { - const __dirname = getDirnameFromImportMeta(import.meta.url); - const readmePath = path.resolve(__dirname, '..', 'README.md'); - const readmeContent = normalizeNewlines( - await fs.readFile(readmePath, 'utf8'), - ); - return readmeContent +export const getThirdPartyExtensions = async (readmePath) => + normalizeNewlines(await fs.readFile(readmePath, 'utf8')) .split('## Third-Party Extensions\n\n')[1] .split('\n\n')[0] .split('\n') @@ -153,4 +149,3 @@ export const getThirdPartyExtensions = async () => { }, }; }); -}; diff --git a/tests/readme.test.js b/tests/readme.test.js index 8ba82f551..0f95718bf 100644 --- a/tests/readme.test.js +++ b/tests/readme.test.js @@ -48,7 +48,8 @@ describe('README icons assets must be consistent with Github themes', () => { }); test('README third party extensions must be alphabetically sorted', async () => { - const thirdPartyExtensions = await getThirdPartyExtensions(); + const readmePath = path.join(root, 'README.md'); + const thirdPartyExtensions = await getThirdPartyExtensions(readmePath); assert.ok(thirdPartyExtensions.length > 0); const thirdPartyExtensionsNames = thirdPartyExtensions.map(