From 7bbc0a8c98644f777eb433e6f6bc55883195b994 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sun, 28 Jul 2024 23:08:40 +0530 Subject: [PATCH 01/44] tools test added --- scripts/build-tools.js | 2 +- scripts/tools/combine-tools.js | 13 +- tests/fixtures/tools/automated-tools.json | 17 +++ tests/fixtures/tools/manual-tools.json | 12 ++ tests/tools/combine-tools.test.js | 149 ++++++++++++++++++++++ 5 files changed, 182 insertions(+), 11 deletions(-) create mode 100644 tests/fixtures/tools/automated-tools.json create mode 100644 tests/fixtures/tools/manual-tools.json create mode 100644 tests/tools/combine-tools.test.js diff --git a/scripts/build-tools.js b/scripts/build-tools.js index 363e3418816..f3997b06d1d 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -14,7 +14,7 @@ const buildTools = async () => { resolve(__dirname, '../config', 'tools-automated.json'), JSON.stringify(automatedTools, null, ' ') ); - await combineTools(automatedTools, manualTools); + await combineTools(automatedTools, manualTools, resolve(__dirname, '../../config', 'tools.json'), resolve(__dirname, '../../config', 'all-tags.json')); } catch (err) { console.log(err); throw err diff --git a/scripts/tools/combine-tools.js b/scripts/tools/combine-tools.js index f929f00095b..602262428fa 100644 --- a/scripts/tools/combine-tools.js +++ b/scripts/tools/combine-tools.js @@ -5,7 +5,6 @@ const fs = require('fs') const schema = require("./tools-schema.json"); const Ajv = require("ajv") const addFormats = require("ajv-formats") -const { resolve } = require('path'); const Fuse = require("fuse.js"); const ajv = new Ajv() addFormats(ajv, ["uri"]) @@ -106,7 +105,7 @@ const getFinalTool = async (toolObject) => { // Combine the automated tools and manual tools list into single JSON object file, and // lists down all the language and technology tags in one JSON file. -const combineTools = async (automatedTools, manualTools) => { +const combineTools = async (automatedTools, manualTools, toolsPath, tagsPath) => { for (const key in automatedTools) { let finalToolsList = []; if (automatedTools[key].toolsList.length) { @@ -136,14 +135,8 @@ const combineTools = async (automatedTools, manualTools) => { finalToolsList.sort((tool, anotherTool) => tool.title.localeCompare(anotherTool.title)); finalTools[key].toolsList = finalToolsList } - fs.writeFileSync( - resolve(__dirname, '../../config', 'tools.json'), - JSON.stringify(finalTools) - ); - fs.writeFileSync( - resolve(__dirname, '../../config', 'all-tags.json'), - JSON.stringify({ languages: languageList, technologies: technologyList }), - ) + fs.writeFileSync(toolsPath,JSON.stringify(finalTools)); + fs.writeFileSync(tagsPath,JSON.stringify({ languages: languageList, technologies: technologyList }),) } module.exports = { combineTools } \ No newline at end of file diff --git a/tests/fixtures/tools/automated-tools.json b/tests/fixtures/tools/automated-tools.json new file mode 100644 index 00000000000..1184da03e71 --- /dev/null +++ b/tests/fixtures/tools/automated-tools.json @@ -0,0 +1,17 @@ +{ + "category1": { + "description": "Sample Category", + "toolsList": [ + { + "title": "Tool B", + "filters": { + "language": "Python", + "technology": ["Flask"] + }, + "links": { + "repoUrl": "https://github.com/asyncapi/tool-b" + } + } + ] + } +} diff --git a/tests/fixtures/tools/manual-tools.json b/tests/fixtures/tools/manual-tools.json new file mode 100644 index 00000000000..47469bc1a7e --- /dev/null +++ b/tests/fixtures/tools/manual-tools.json @@ -0,0 +1,12 @@ +[ + { + "title": "Tool A", + "filters": { + "language": "JavaScript", + "technology": ["Node.js"] + }, + "links": { + "repoUrl": "https://github.com/asyncapi/tool-a" + } + } +] diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js new file mode 100644 index 00000000000..352f8e16f32 --- /dev/null +++ b/tests/tools/combine-tools.test.js @@ -0,0 +1,149 @@ +const fs = require('fs'); +const path = require('path'); +const { combineTools } = require('../../scripts/tools/combine-tools'); +const Ajv = require("ajv"); +const addFormats = require("ajv-formats"); + +// Mock dependencies +jest.mock('../../scripts/tools/tags-color', () => ({ + languagesColor: [ + { name: 'JavaScript', color: 'bg-[#57f281]', borderColor: 'border-[#37f069]' }, + { name: 'Python', color: 'bg-[#3572A5]', borderColor: 'border-[#3572A5]' } + ], + technologiesColor: [ + { name: 'Node.js', color: 'bg-[#61d0f2]', borderColor: 'border-[#40ccf7]' }, + { name: 'Flask', color: 'bg-[#000000]', borderColor: 'border-[#FFFFFF]' } + ] +})); + +jest.mock('../../scripts/tools/categorylist', () => ({ + categoryList: [ + { name: 'category1', description: 'Sample Category 1' }, + { name: 'category2', description: 'Sample Category 2' } + ] +})); + +jest.mock('../../scripts/tools/tools-object', () => ({ + createToolObject: jest.fn((tool, _, __, isAsyncAPIrepo) => { + return { ...tool, isAsyncAPIrepo }; + }) +})); + +const ajv = new Ajv(); +addFormats(ajv, ["uri"]); + +const readJSON = (filePath) => JSON.parse(fs.readFileSync(filePath, 'utf-8')); + +describe('combineTools function', () => { + const toolsPath = path.join(__dirname, '../', 'fixtures', 'tools', 'tools.json'); + const tagsPath = path.join(__dirname, '../', 'fixtures', 'tools', 'tags.json'); + const manualToolsPath = path.join(__dirname, '../', 'fixtures', 'tools', 'manual-tools.json'); + const automatedToolsPath = path.join(__dirname, '../', 'fixtures', 'tools', 'automated-tools.json'); + + let manualTools; + let automatedTools; + + beforeAll(() => { + manualTools = readJSON(manualToolsPath); + automatedTools = readJSON(automatedToolsPath); + }); + + afterAll(() => { + // Clean up by removing the created files + if (fs.existsSync(toolsPath)) fs.unlinkSync(toolsPath); + if (fs.existsSync(tagsPath)) fs.unlinkSync(tagsPath); + }); + + test('should combine tools and create correct JSON files', async () => { + await combineTools(automatedTools, manualTools, toolsPath, tagsPath); + + // Verify toolsPath file exists and has correct content + const combinedTools = readJSON(toolsPath); + expect(combinedTools).toHaveProperty('category1'); + + // Verify tagsPath file exists and has correct content + const tagsData = readJSON(tagsPath); + expect(tagsData).toHaveProperty('languages'); + expect(tagsData).toHaveProperty('technologies'); + expect(tagsData.languages).toContainEqual({ + name: 'JavaScript', + color: 'bg-[#57f281]', + borderColor: 'border-[#37f069]' + }); + expect(tagsData.languages).toContainEqual({ + name: 'Python', + color: 'bg-[#3572A5]', + borderColor: 'border-[#3572A5]' + }); + expect(tagsData.technologies).toContainEqual({ + name: 'Node.js', + color: 'bg-[#61d0f2]', + borderColor: 'border-[#40ccf7]' + }); + expect(tagsData.technologies).toContainEqual({ + name: 'Flask', + color: 'bg-[#000000]', + borderColor: 'border-[#FFFFFF]' + }); + }); + + test('should handle tools with missing language or technology', async () => { + const manualToolsWithMissingData = [ + { + title: 'Tool C', + filters: {}, + links: { repoUrl: 'https://github.com/asyncapi/tool-c' } + } + ]; + + await combineTools({}, manualToolsWithMissingData, toolsPath, tagsPath); + + const combinedTools = readJSON(toolsPath); + expect(combinedTools).toHaveProperty('category1'); + }); + + test('should validate manual tools and skip invalid ones', async () => { + const invalidManualTools = [ + { + title: 'Invalid Tool', + filters: { + language: 'Invalid Language' + }, + links: {} + } + ]; + + await combineTools({}, invalidManualTools, toolsPath, tagsPath); + + const combinedTools = readJSON(toolsPath); + expect(combinedTools).toHaveProperty('category1'); + }); + + + test('should sort tools alphabetically by title', async () => { + const manualToolsToSort = { + category1: { + description: 'Sample Category', + toolsList: [ + { + title: 'Tool Z', + filters: { language: 'JavaScript' }, + links: { repoUrl: 'https://github.com/asyncapi/tool-z' } + }, + { + title: 'Tool A', + filters: { language: 'Python' }, + links: { repoUrl: 'https://github.com/asyncapi/tool-a' } + } + ] + } + }; + + await combineTools(manualToolsToSort, {}, toolsPath, tagsPath); + + const combinedTools = readJSON(toolsPath); + const toolTitles = combinedTools.category1.toolsList.map(tool => tool.title); + expect(toolTitles).toEqual(['Tool A', 'Tool Z']); + }); + +}); From 527cf9f4bfafbc37f38ae7e5b1b9090add38bf1a Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 29 Jul 2024 11:40:11 +0530 Subject: [PATCH 02/44] tools test updated for errors --- tests/tools/combine-tools.test.js | 70 +++++++++++++++++-------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 352f8e16f32..0e8cdff8fb6 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -1,10 +1,8 @@ const fs = require('fs'); const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); -const Ajv = require("ajv"); -const addFormats = require("ajv-formats"); +const { createToolObject } = require('../../scripts/tools/tools-object'); -// Mock dependencies jest.mock('../../scripts/tools/tags-color', () => ({ languagesColor: [ { name: 'JavaScript', color: 'bg-[#57f281]', borderColor: 'border-[#37f069]' }, @@ -29,9 +27,6 @@ jest.mock('../../scripts/tools/tools-object', () => ({ }) })); -const ajv = new Ajv(); -addFormats(ajv, ["uri"]); - const readJSON = (filePath) => JSON.parse(fs.readFileSync(filePath, 'utf-8')); describe('combineTools function', () => { @@ -43,25 +38,26 @@ describe('combineTools function', () => { let manualTools; let automatedTools; + let consoleErrorMock; + beforeAll(() => { manualTools = readJSON(manualToolsPath); automatedTools = readJSON(automatedToolsPath); + + consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {}); }); afterAll(() => { - // Clean up by removing the created files if (fs.existsSync(toolsPath)) fs.unlinkSync(toolsPath); if (fs.existsSync(tagsPath)) fs.unlinkSync(tagsPath); }); - test('should combine tools and create correct JSON files', async () => { + it('should combine tools and create correct JSON files', async () => { await combineTools(automatedTools, manualTools, toolsPath, tagsPath); - // Verify toolsPath file exists and has correct content const combinedTools = readJSON(toolsPath); expect(combinedTools).toHaveProperty('category1'); - // Verify tagsPath file exists and has correct content const tagsData = readJSON(tagsPath); expect(tagsData).toHaveProperty('languages'); expect(tagsData).toHaveProperty('technologies'); @@ -87,7 +83,7 @@ describe('combineTools function', () => { }); }); - test('should handle tools with missing language or technology', async () => { + it('should handle tools with missing language or technology', async () => { const manualToolsWithMissingData = [ { title: 'Tool C', @@ -102,25 +98,7 @@ describe('combineTools function', () => { expect(combinedTools).toHaveProperty('category1'); }); - test('should validate manual tools and skip invalid ones', async () => { - const invalidManualTools = [ - { - title: 'Invalid Tool', - filters: { - language: 'Invalid Language' - }, - links: {} - } - ]; - - await combineTools({}, invalidManualTools, toolsPath, tagsPath); - - const combinedTools = readJSON(toolsPath); - expect(combinedTools).toHaveProperty('category1'); - }); - - - test('should sort tools alphabetically by title', async () => { + it('should sort tools alphabetically by title', async () => { const manualToolsToSort = { category1: { description: 'Sample Category', @@ -146,4 +124,34 @@ describe('combineTools function', () => { expect(toolTitles).toEqual(['Tool A', 'Tool Z']); }); -}); + + it('should log validation errors to console.error', async () => { + const invalidTool = { title: 'Invalid Tool' }; + const automatedTools = { + 'category1': { + description: 'Category 1 Description', + toolsList: [] + } + }; + const manualTools = { + 'category1': { + toolsList: [invalidTool] + } + }; + + createToolObject.mockImplementation((tool) => Promise.resolve(tool)); + + await combineTools(automatedTools, manualTools, toolsPath, tagsPath); + + const errorCalls = console.error.mock.calls; + + expect(errorCalls[0][0]).toBe('Script is not failing, it is just dropping errors for further investigation'); + expect(errorCalls[1][0]).toBe('Invalid Invalid Tool .asyncapi-tool file.'); + expect(errorCalls[2][0]).toBe('Located in manual-tools.json file'); + expect(errorCalls[3][0]).toEqual(expect.stringContaining('Validation errors:')); + + expect(fs.existsSync(toolsPath)).toBe(true); + expect(fs.existsSync(tagsPath)).toBe(true); + }); + +}); \ No newline at end of file From 878023a0f87b33fdfb51c675b35c24de6467984a Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Wed, 31 Jul 2024 18:43:24 +0530 Subject: [PATCH 03/44] tools test upadted --- tests/tools/combine-tools.test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 0e8cdff8fb6..5f717796909 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -154,4 +154,34 @@ describe('combineTools function', () => { expect(fs.existsSync(tagsPath)).toBe(true); }); + it('should handle tools with multiple languages, including new ones', async () => { + const toolWithMultipleLanguages = { + title: 'Multi-Language Tool', + filters: { + language: ['JavaScript', 'Python', 'NewLanguage'], + technology: ['Node.js'] + }, + links: { repoUrl: 'https://github.com/example/multi-language-tool' } + }; + + const automatedTools = { + 'category1': { + description: 'Category 1 Description', + toolsList: [toolWithMultipleLanguages] + } + }; + + await combineTools(automatedTools, {}, toolsPath, tagsPath); + + const combinedTools = readJSON(toolsPath); + const tool = combinedTools.category1.toolsList[0]; + + expect(tool.filters.language).toHaveLength(3); + expect(tool.filters.language).toContainEqual(expect.objectContaining({ name: 'JavaScript' })); + expect(tool.filters.language).toContainEqual(expect.objectContaining({ name: 'Python' })); + expect(tool.filters.language).toContainEqual(expect.objectContaining({ name: 'NewLanguage' })); + + const tagsData = readJSON(tagsPath); + expect(tagsData.languages).toContainEqual(expect.objectContaining({ name: 'NewLanguage' })); + }); }); \ No newline at end of file From be808852f2b4fdb113d088fd0af81993e4a0597c Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 31 Aug 2024 22:46:40 +0530 Subject: [PATCH 04/44] refactor build-tools --- scripts/build-tools.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/build-tools.js b/scripts/build-tools.js index f3997b06d1d..e8c380a6298 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -6,15 +6,19 @@ const manualTools = require('../config/tools-manual.json') const fs = require('fs'); const { resolve } = require('path'); +let toolsPath = resolve(__dirname, '../../config', 'tools.json') +let tagsPath = resolve(__dirname, '../../config', 'all-tags.json') +let automatedToolsPath = resolve(__dirname, '../config', 'tools-automated.json') + const buildTools = async () => { try { let githubExtractData = await getData(); let automatedTools = await convertTools(githubExtractData); fs.writeFileSync( - resolve(__dirname, '../config', 'tools-automated.json'), + automatedToolsPath, JSON.stringify(automatedTools, null, ' ') ); - await combineTools(automatedTools, manualTools, resolve(__dirname, '../../config', 'tools.json'), resolve(__dirname, '../../config', 'all-tags.json')); + await combineTools(automatedTools, manualTools, toolsPath, tagsPath); } catch (err) { console.log(err); throw err From 1dfd1886cae1a1627a5b23efd91dc5f50ebf7d61 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 21 Sep 2024 11:06:41 +0530 Subject: [PATCH 05/44] 87% coverage --- tests/tools/combine-tools.test.js | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 5f717796909..754b7f6cfbb 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -184,4 +184,46 @@ describe('combineTools function', () => { const tagsData = readJSON(tagsPath); expect(tagsData.languages).toContainEqual(expect.objectContaining({ name: 'NewLanguage' })); }); + + it('should add a new language and technology when not found in the existing lists', async () => { + const toolWithNewTags = { + title: 'New Tags Tool', + filters: { + language: 'NewLanguage', + technology: ['NewTechnology'] + }, + links: { repoUrl: 'https://github.com/example/new-tags-tool' } + }; + + const automatedTools = { + 'category1': { + description: 'Category 1 Description', + toolsList: [toolWithNewTags] + } + }; + + await combineTools(automatedTools, {}, toolsPath, tagsPath); + + const combinedTools = readJSON(toolsPath); + const tool = combinedTools.category1.toolsList[0]; + + expect(tool.filters.language).toHaveLength(1); + expect(tool.filters.language).toContainEqual(expect.objectContaining({ name: 'NewLanguage' })); + + expect(tool.filters.technology).toHaveLength(1); + expect(tool.filters.technology).toContainEqual(expect.objectContaining({ name: 'NewTechnology' })); + + const tagsData = readJSON(tagsPath); + expect(tagsData.languages).toContainEqual({ + name: 'NewLanguage', + color: 'bg-[#57f281]', + borderColor: 'border-[#37f069]' + }); + expect(tagsData.technologies).toContainEqual({ + name: 'NewTechnology', + color: 'bg-[#61d0f2]', + borderColor: 'border-[#40ccf7]' + }); + }); + }); \ No newline at end of file From 103d643497360fa0c808a7d470262a0abba6ab6e Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 21 Sep 2024 11:18:26 +0530 Subject: [PATCH 06/44] fewgw --- tests/tools/combine-tools.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 754b7f6cfbb..64a090eb17c 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -225,5 +225,5 @@ describe('combineTools function', () => { borderColor: 'border-[#40ccf7]' }); }); - + }); \ No newline at end of file From b3a87ddc518fb0696356a63d2ec5519ca55e3d09 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 21 Sep 2024 11:20:36 +0530 Subject: [PATCH 07/44] fewgw --- tests/tools/combine-tools.test.js | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 64a090eb17c..9d4bc6d794d 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -225,5 +225,37 @@ describe('combineTools function', () => { borderColor: 'border-[#40ccf7]' }); }); - + it('should add a new language when it is not found in the existing languages list', async () => { + const toolWithNewLanguage = { + title: 'New Language Tool', + filters: { + language: 'Go', // A language that is not in the mocked `languagesColor` list + technology: ['Node.js'] + }, + links: { repoUrl: 'https://github.com/example/new-language-tool' } + }; + + const automatedTools = { + 'category1': { + description: 'Category 1 Description', + toolsList: [toolWithNewLanguage] + } + }; + + await combineTools(automatedTools, {}, toolsPath, tagsPath); + + const combinedTools = readJSON(toolsPath); + const tool = combinedTools.category1.toolsList[0]; + + expect(tool.filters.language).toHaveLength(1); + expect(tool.filters.language).toContainEqual(expect.objectContaining({ name: 'Go' })); + + const tagsData = readJSON(tagsPath); + expect(tagsData.languages).toContainEqual({ + name: 'Go', + color: 'bg-[#57f281]', // The default color that gets added + borderColor: 'border-[#37f069]' + }); + }); + }); \ No newline at end of file From 8357f569630ec56163733ac7c9fdb784c37c75aa Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 21 Sep 2024 11:34:41 +0530 Subject: [PATCH 08/44] fewgwfwf --- tests/tools/combine-tools.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 9d4bc6d794d..b1a61e65348 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -229,7 +229,7 @@ describe('combineTools function', () => { const toolWithNewLanguage = { title: 'New Language Tool', filters: { - language: 'Go', // A language that is not in the mocked `languagesColor` list + language: 'Go', technology: ['Node.js'] }, links: { repoUrl: 'https://github.com/example/new-language-tool' } @@ -253,7 +253,7 @@ describe('combineTools function', () => { const tagsData = readJSON(tagsPath); expect(tagsData.languages).toContainEqual({ name: 'Go', - color: 'bg-[#57f281]', // The default color that gets added + color: 'bg-[#57f281]', borderColor: 'border-[#37f069]' }); }); From db96f45ead64055c039e416ab11ae3d7f17c0772 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 21 Sep 2024 15:30:30 +0530 Subject: [PATCH 09/44] wf --- tests/tools/combine-tools.test.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index b1a61e65348..c81dd5b47e8 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -3,6 +3,16 @@ const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); const { createToolObject } = require('../../scripts/tools/tools-object'); +// jest.mock('ajv', () => { +// const Ajv = jest.fn(); +// Ajv.prototype.compile = jest.fn().mockReturnValue(() => true); +// return Ajv; +// }); + +// jest.mock('ajv-formats', () => { +// return jest.fn(); +// }); + jest.mock('../../scripts/tools/tags-color', () => ({ languagesColor: [ { name: 'JavaScript', color: 'bg-[#57f281]', borderColor: 'border-[#37f069]' }, From 2b392d1b30202a52c8a9a4884f43daa7e42d772b Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sun, 29 Sep 2024 19:11:09 +0530 Subject: [PATCH 10/44] fwefgwe --- tests/tools/combine-tools.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index c81dd5b47e8..611128b4393 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -32,7 +32,7 @@ jest.mock('../../scripts/tools/categorylist', () => ({ })); jest.mock('../../scripts/tools/tools-object', () => ({ - createToolObject: jest.fn((tool, _, __, isAsyncAPIrepo) => { + createToolObject: jest.fn((tool, isAsyncAPIrepo) => { return { ...tool, isAsyncAPIrepo }; }) })); From 877990edb45fe30e7134f7c46a6773335c72cf6d Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sun, 29 Sep 2024 22:33:36 +0530 Subject: [PATCH 11/44] test update --- tests/tools/combine-tools.test.js | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 611128b4393..153ffd6239e 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -3,16 +3,6 @@ const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); const { createToolObject } = require('../../scripts/tools/tools-object'); -// jest.mock('ajv', () => { -// const Ajv = jest.fn(); -// Ajv.prototype.compile = jest.fn().mockReturnValue(() => true); -// return Ajv; -// }); - -// jest.mock('ajv-formats', () => { -// return jest.fn(); -// }); - jest.mock('../../scripts/tools/tags-color', () => ({ languagesColor: [ { name: 'JavaScript', color: 'bg-[#57f281]', borderColor: 'border-[#37f069]' }, @@ -31,11 +21,7 @@ jest.mock('../../scripts/tools/categorylist', () => ({ ] })); -jest.mock('../../scripts/tools/tools-object', () => ({ - createToolObject: jest.fn((tool, isAsyncAPIrepo) => { - return { ...tool, isAsyncAPIrepo }; - }) -})); +jest.mock('../../scripts/tools/tools-object'); const readJSON = (filePath) => JSON.parse(fs.readFileSync(filePath, 'utf-8')); @@ -47,7 +33,6 @@ describe('combineTools function', () => { let manualTools; let automatedTools; - let consoleErrorMock; beforeAll(() => { @@ -134,7 +119,6 @@ describe('combineTools function', () => { expect(toolTitles).toEqual(['Tool A', 'Tool Z']); }); - it('should log validation errors to console.error', async () => { const invalidTool = { title: 'Invalid Tool' }; const automatedTools = { @@ -181,6 +165,8 @@ describe('combineTools function', () => { } }; + createToolObject.mockImplementation((tool) => Promise.resolve(tool)); + await combineTools(automatedTools, {}, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); @@ -212,6 +198,8 @@ describe('combineTools function', () => { } }; + createToolObject.mockImplementation((tool) => Promise.resolve(tool)); + await combineTools(automatedTools, {}, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); @@ -235,6 +223,7 @@ describe('combineTools function', () => { borderColor: 'border-[#40ccf7]' }); }); + it('should add a new language when it is not found in the existing languages list', async () => { const toolWithNewLanguage = { title: 'New Language Tool', @@ -251,7 +240,9 @@ describe('combineTools function', () => { toolsList: [toolWithNewLanguage] } }; - + + createToolObject.mockImplementation((tool) => Promise.resolve(tool)); + await combineTools(automatedTools, {}, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); @@ -267,5 +258,4 @@ describe('combineTools function', () => { borderColor: 'border-[#37f069]' }); }); - -}); \ No newline at end of file +}); From 88b149129c54e5312dd63c3cc8bc4001febfc0e7 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sun, 29 Sep 2024 23:28:59 +0530 Subject: [PATCH 12/44] test update --- tests/tools/combine-tools.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 153ffd6239e..70ccfb58d35 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -3,6 +3,19 @@ const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); const { createToolObject } = require('../../scripts/tools/tools-object'); +const Ajv = require('ajv'); + +// Mock the entire Ajv module +jest.mock('ajv', () => { + return jest.fn().mockImplementation(() => { + return { + compile: jest.fn() + }; + }); +}); +jest.mock('ajv-formats', () => { + return jest.fn(); +}); jest.mock('../../scripts/tools/tags-color', () => ({ languagesColor: [ { name: 'JavaScript', color: 'bg-[#57f281]', borderColor: 'border-[#37f069]' }, @@ -120,6 +133,12 @@ describe('combineTools function', () => { }); it('should log validation errors to console.error', async () => { + const mockValidate = jest.fn().mockReturnValue(true); + mockValidate.errors = [{ message: 'Invalid tool' }]; + + // Get the mocked Ajv instance and set the compile method to return our mockValidate + const ajvInstance = new Ajv(); + ajvInstance.compile.mockReturnValue(mockValidate); const invalidTool = { title: 'Invalid Tool' }; const automatedTools = { 'category1': { From dd90f3c018d161abff3a7ab8f203a647c0d142f2 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sun, 29 Sep 2024 23:30:01 +0530 Subject: [PATCH 13/44] test update --- tests/tools/combine-tools.test.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 70ccfb58d35..153ffd6239e 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -3,19 +3,6 @@ const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); const { createToolObject } = require('../../scripts/tools/tools-object'); -const Ajv = require('ajv'); - -// Mock the entire Ajv module -jest.mock('ajv', () => { - return jest.fn().mockImplementation(() => { - return { - compile: jest.fn() - }; - }); -}); -jest.mock('ajv-formats', () => { - return jest.fn(); -}); jest.mock('../../scripts/tools/tags-color', () => ({ languagesColor: [ { name: 'JavaScript', color: 'bg-[#57f281]', borderColor: 'border-[#37f069]' }, @@ -133,12 +120,6 @@ describe('combineTools function', () => { }); it('should log validation errors to console.error', async () => { - const mockValidate = jest.fn().mockReturnValue(true); - mockValidate.errors = [{ message: 'Invalid tool' }]; - - // Get the mocked Ajv instance and set the compile method to return our mockValidate - const ajvInstance = new Ajv(); - ajvInstance.compile.mockReturnValue(mockValidate); const invalidTool = { title: 'Invalid Tool' }; const automatedTools = { 'category1': { From c347dbf8ddd0987eb815ae1be3faa5a789cce1b5 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sun, 29 Sep 2024 23:34:05 +0530 Subject: [PATCH 14/44] test update again --- tests/tools/combine-tools.test.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 153ffd6239e..202259c564e 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -1,7 +1,6 @@ const fs = require('fs'); const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); -const { createToolObject } = require('../../scripts/tools/tools-object'); jest.mock('../../scripts/tools/tags-color', () => ({ languagesColor: [ @@ -21,8 +20,6 @@ jest.mock('../../scripts/tools/categorylist', () => ({ ] })); -jest.mock('../../scripts/tools/tools-object'); - const readJSON = (filePath) => JSON.parse(fs.readFileSync(filePath, 'utf-8')); describe('combineTools function', () => { @@ -33,13 +30,10 @@ describe('combineTools function', () => { let manualTools; let automatedTools; - let consoleErrorMock; beforeAll(() => { manualTools = readJSON(manualToolsPath); automatedTools = readJSON(automatedToolsPath); - - consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {}); }); afterAll(() => { @@ -120,6 +114,9 @@ describe('combineTools function', () => { }); it('should log validation errors to console.error', async () => { + + let consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {}); + const invalidTool = { title: 'Invalid Tool' }; const automatedTools = { 'category1': { @@ -133,8 +130,6 @@ describe('combineTools function', () => { } }; - createToolObject.mockImplementation((tool) => Promise.resolve(tool)); - await combineTools(automatedTools, manualTools, toolsPath, tagsPath); const errorCalls = console.error.mock.calls; @@ -164,8 +159,6 @@ describe('combineTools function', () => { toolsList: [toolWithMultipleLanguages] } }; - - createToolObject.mockImplementation((tool) => Promise.resolve(tool)); await combineTools(automatedTools, {}, toolsPath, tagsPath); @@ -197,8 +190,6 @@ describe('combineTools function', () => { toolsList: [toolWithNewTags] } }; - - createToolObject.mockImplementation((tool) => Promise.resolve(tool)); await combineTools(automatedTools, {}, toolsPath, tagsPath); @@ -241,8 +232,6 @@ describe('combineTools function', () => { } }; - createToolObject.mockImplementation((tool) => Promise.resolve(tool)); - await combineTools(automatedTools, {}, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); From 71e4f13beb37ff16051d724e44509ceb1610ad55 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 30 Sep 2024 00:20:22 +0530 Subject: [PATCH 15/44] coverage 98% --- tests/tools/combine-tools.test.js | 51 ++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 202259c564e..5d106d903c9 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -2,6 +2,24 @@ const fs = require('fs'); const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); +jest.mock('ajv', () => { + const Ajv = jest.fn(); + Ajv.prototype.compile = jest.fn().mockImplementation(() => { + return (data) => { + + if (data.title === 'Invalid Tool') { + return false; + } + return true; + }; + }); + return Ajv; +}); + +jest.mock('ajv-formats', () => { + return jest.fn(); +}); + jest.mock('../../scripts/tools/tags-color', () => ({ languagesColor: [ { name: 'JavaScript', color: 'bg-[#57f281]', borderColor: 'border-[#37f069]' }, @@ -34,6 +52,7 @@ describe('combineTools function', () => { beforeAll(() => { manualTools = readJSON(manualToolsPath); automatedTools = readJSON(automatedToolsPath); + }); afterAll(() => { @@ -114,7 +133,6 @@ describe('combineTools function', () => { }); it('should log validation errors to console.error', async () => { - let consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {}); const invalidTool = { title: 'Invalid Tool' }; @@ -141,6 +159,8 @@ describe('combineTools function', () => { expect(fs.existsSync(toolsPath)).toBe(true); expect(fs.existsSync(tagsPath)).toBe(true); + + consoleErrorMock.mockRestore(); }); it('should handle tools with multiple languages, including new ones', async () => { @@ -247,4 +267,33 @@ describe('combineTools function', () => { borderColor: 'border-[#37f069]' }); }); + + it('should handle valid tool objects', async () => { + + const validTool = { + title: 'Valid Tool', + filters: { + language: 'JavaScript', + technology: ['Node.js'] + }, + links: { repoUrl: 'https://github.com/asyncapi/valid-tool' } + }; + + const automatedTools = { + category1: { + description: 'Category 1 Description', + toolsList: [] + } + }; + + const manualTools = { + category1: { + toolsList: [validTool] + } + }; + + await combineTools(automatedTools, manualTools, toolsPath, tagsPath); + + }); + }); From 03e0664591a5471d03287442fbb6af272f539b1f Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 30 Sep 2024 00:28:45 +0530 Subject: [PATCH 16/44] fefefge --- tests/tools/combine-tools.test.js | 65 ++++++++++++++++--------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 5d106d903c9..71ec1edd616 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -3,19 +3,12 @@ const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); jest.mock('ajv', () => { - const Ajv = jest.fn(); - Ajv.prototype.compile = jest.fn().mockImplementation(() => { - return (data) => { - - if (data.title === 'Invalid Tool') { - return false; - } - return true; - }; - }); - return Ajv; + return jest.fn().mockImplementation(() => ({ + compile: jest.fn().mockImplementation(() => (data) => data.title !== 'Invalid Tool'), + })); }); + jest.mock('ajv-formats', () => { return jest.fn(); }); @@ -133,7 +126,7 @@ describe('combineTools function', () => { }); it('should log validation errors to console.error', async () => { - let consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {}); + let consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => { }); const invalidTool = { title: 'Invalid Tool' }; const automatedTools = { @@ -172,7 +165,7 @@ describe('combineTools function', () => { }, links: { repoUrl: 'https://github.com/example/multi-language-tool' } }; - + const automatedTools = { 'category1': { description: 'Category 1 Description', @@ -181,15 +174,15 @@ describe('combineTools function', () => { }; await combineTools(automatedTools, {}, toolsPath, tagsPath); - + const combinedTools = readJSON(toolsPath); const tool = combinedTools.category1.toolsList[0]; - + expect(tool.filters.language).toHaveLength(3); expect(tool.filters.language).toContainEqual(expect.objectContaining({ name: 'JavaScript' })); expect(tool.filters.language).toContainEqual(expect.objectContaining({ name: 'Python' })); expect(tool.filters.language).toContainEqual(expect.objectContaining({ name: 'NewLanguage' })); - + const tagsData = readJSON(tagsPath); expect(tagsData.languages).toContainEqual(expect.objectContaining({ name: 'NewLanguage' })); }); @@ -203,7 +196,7 @@ describe('combineTools function', () => { }, links: { repoUrl: 'https://github.com/example/new-tags-tool' } }; - + const automatedTools = { 'category1': { description: 'Category 1 Description', @@ -212,16 +205,16 @@ describe('combineTools function', () => { }; await combineTools(automatedTools, {}, toolsPath, tagsPath); - + const combinedTools = readJSON(toolsPath); const tool = combinedTools.category1.toolsList[0]; - + expect(tool.filters.language).toHaveLength(1); expect(tool.filters.language).toContainEqual(expect.objectContaining({ name: 'NewLanguage' })); - + expect(tool.filters.technology).toHaveLength(1); expect(tool.filters.technology).toContainEqual(expect.objectContaining({ name: 'NewTechnology' })); - + const tagsData = readJSON(tagsPath); expect(tagsData.languages).toContainEqual({ name: 'NewLanguage', @@ -244,7 +237,7 @@ describe('combineTools function', () => { }, links: { repoUrl: 'https://github.com/example/new-language-tool' } }; - + const automatedTools = { 'category1': { description: 'Category 1 Description', @@ -253,13 +246,13 @@ describe('combineTools function', () => { }; await combineTools(automatedTools, {}, toolsPath, tagsPath); - + const combinedTools = readJSON(toolsPath); const tool = combinedTools.category1.toolsList[0]; - + expect(tool.filters.language).toHaveLength(1); expect(tool.filters.language).toContainEqual(expect.objectContaining({ name: 'Go' })); - + const tagsData = readJSON(tagsPath); expect(tagsData.languages).toContainEqual({ name: 'Go', @@ -269,7 +262,6 @@ describe('combineTools function', () => { }); it('should handle valid tool objects', async () => { - const validTool = { title: 'Valid Tool', filters: { @@ -278,22 +270,33 @@ describe('combineTools function', () => { }, links: { repoUrl: 'https://github.com/asyncapi/valid-tool' } }; - + const automatedTools = { category1: { description: 'Category 1 Description', toolsList: [] } }; - + const manualTools = { category1: { toolsList: [validTool] } }; - + await combineTools(automatedTools, manualTools, toolsPath, tagsPath); - + + + const tagsData = readJSON(tagsPath); + expect(tagsData.languages).toContainEqual({ + name: 'JavaScript', + color: 'bg-[#57f281]', + borderColor: 'border-[#37f069]' + }); + expect(tagsData.technologies).toContainEqual({ + name: 'Node.js', + color: 'bg-[#61d0f2]', + borderColor: 'border-[#40ccf7]' + }); }); - }); From 18e9d987255b1dd8d7966267c99e9814dedee14b Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 30 Sep 2024 00:32:13 +0530 Subject: [PATCH 17/44] 100% coverage --- tests/tools/combine-tools.test.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 71ec1edd616..78a7c048cf0 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -299,4 +299,35 @@ describe('combineTools function', () => { borderColor: 'border-[#40ccf7]' }); }); + + it('should handle tool objects without repoUrl', async () => { + const toolWithoutRepoUrl = { + title: 'Tool Without Repo', + filters: { + language: 'Python', + technology: ['Flask'] + }, + links: {} + }; + + const automatedTools = { + category1: { + description: 'Category 1 Description', + toolsList: [] + } + }; + + const manualTools = { + category1: { + toolsList: [toolWithoutRepoUrl] + } + }; + + await combineTools(automatedTools, manualTools, toolsPath, tagsPath); + + const combinedTools = readJSON(toolsPath); + const tool = combinedTools.category1.toolsList[0]; + + expect(tool.isAsyncAPIrepo).toBeUndefined(); + }); }); From b3ae94b7b6468581cf7438c2db690e46fc496801 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 30 Sep 2024 12:32:29 +0530 Subject: [PATCH 18/44] test cases for error added --- scripts/tools/combine-tools.js | 57 ++++++++++-------- tests/tools/combine-tools.test.js | 98 ++++++++++++++++++++++++++++--- 2 files changed, 122 insertions(+), 33 deletions(-) diff --git a/scripts/tools/combine-tools.js b/scripts/tools/combine-tools.js index 602262428fa..a251c7da049 100644 --- a/scripts/tools/combine-tools.js +++ b/scripts/tools/combine-tools.js @@ -6,6 +6,7 @@ const schema = require("./tools-schema.json"); const Ajv = require("ajv") const addFormats = require("ajv-formats") const Fuse = require("fuse.js"); +const { error } = require("console"); const ajv = new Ajv() addFormats(ajv, ["uri"]) const validate = ajv.compile(schema) @@ -106,37 +107,41 @@ const getFinalTool = async (toolObject) => { // Combine the automated tools and manual tools list into single JSON object file, and // lists down all the language and technology tags in one JSON file. const combineTools = async (automatedTools, manualTools, toolsPath, tagsPath) => { - for (const key in automatedTools) { - let finalToolsList = []; - if (automatedTools[key].toolsList.length) { - for (const tool of automatedTools[key].toolsList) { - finalToolsList.push(await getFinalTool(tool)) + try { + for (const key in automatedTools) { + let finalToolsList = []; + if (automatedTools[key].toolsList.length) { + for (const tool of automatedTools[key].toolsList) { + finalToolsList.push(await getFinalTool(tool)) + } } - } - if (manualTools[key] && manualTools[key].toolsList.length) { - for (const tool of manualTools[key].toolsList) { - let isAsyncAPIrepo; - const isValid = await validate(tool) - if (isValid) { - if (tool?.links?.repoUrl) { - const url = new URL(tool.links.repoUrl) - isAsyncAPIrepo = url.href.startsWith("https://github.com/asyncapi/") - } else isAsyncAPIrepo = false - let toolObject = await createToolObject(tool, "", "", isAsyncAPIrepo) - finalToolsList.push(await getFinalTool(toolObject)) - } else { - console.error('Script is not failing, it is just dropping errors for further investigation'); - console.error(`Invalid ${tool.title} .asyncapi-tool file.`); - console.error(`Located in manual-tools.json file`); - console.error('Validation errors:', JSON.stringify(validate.errors, null, 2)); + if (manualTools[key] && manualTools[key].toolsList.length) { + for (const tool of manualTools[key].toolsList) { + let isAsyncAPIrepo; + const isValid = await validate(tool) + if (isValid) { + if (tool?.links?.repoUrl) { + const url = new URL(tool.links.repoUrl) + isAsyncAPIrepo = url.href.startsWith("https://github.com/asyncapi/") + } else isAsyncAPIrepo = false + let toolObject = await createToolObject(tool, "", "", isAsyncAPIrepo) + finalToolsList.push(await getFinalTool(toolObject)) + } else { + console.error('Script is not failing, it is just dropping errors for further investigation'); + console.error(`Invalid ${tool.title} .asyncapi-tool file.`); + console.error(`Located in manual-tools.json file`); + console.error('Validation errors:', JSON.stringify(validate.errors, null, 2)); + } } } + finalToolsList.sort((tool, anotherTool) => tool.title.localeCompare(anotherTool.title)); + finalTools[key].toolsList = finalToolsList } - finalToolsList.sort((tool, anotherTool) => tool.title.localeCompare(anotherTool.title)); - finalTools[key].toolsList = finalToolsList + fs.writeFileSync(toolsPath, JSON.stringify(finalTools)); + fs.writeFileSync(tagsPath, JSON.stringify({ languages: languageList, technologies: technologyList }),) + } catch (err) { + throw new Error(`Error combining tools: ${err}`); } - fs.writeFileSync(toolsPath,JSON.stringify(finalTools)); - fs.writeFileSync(tagsPath,JSON.stringify({ languages: languageList, technologies: technologyList }),) } module.exports = { combineTools } \ No newline at end of file diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 78a7c048cf0..89cf0460755 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -309,25 +309,109 @@ describe('combineTools function', () => { }, links: {} }; - + const automatedTools = { category1: { description: 'Category 1 Description', toolsList: [] } }; - + const manualTools = { category1: { toolsList: [toolWithoutRepoUrl] } }; - + await combineTools(automatedTools, manualTools, toolsPath, tagsPath); - + const combinedTools = readJSON(toolsPath); const tool = combinedTools.category1.toolsList[0]; - - expect(tool.isAsyncAPIrepo).toBeUndefined(); - }); + + expect(tool.isAsyncAPIrepo).toBeUndefined(); + }); + + it('should throw an error when fs.writeFileSync fails', async () => { + let invalidPath = "this/is/not/valid" + + try { + await combineTools(automatedTools, manualTools, invalidPath, invalidPath); + } catch (err) { + expect(err.message).toMatch(/ENOENT|EACCES/); + } + }); + + it('should throw an error when there is an invalid category', async () => { + const invalidAutomatedTools = { + invalidCategory: { + description: 'Invalid Category Description', + toolsList: [] + } + }; + + try { + await combineTools(invalidAutomatedTools, manualTools, toolsPath, tagsPath); + } catch (err) { + expect(err.message).toContain('Error combining tools'); + } + }); + + it('should throw an error when URL parsing fails', async () => { + const manualToolsWithInvalidURL = { + category1: { + toolsList: [ + { + title: 'Tool with Invalid URL', + filters: { language: 'JavaScript' }, + links: { repoUrl: 'invalid-url' } + } + ] + } + }; + + try { + await combineTools(automatedTools, manualToolsWithInvalidURL, toolsPath, tagsPath); + } catch (err) { + expect(err.message).toContain('Invalid URL'); + } + }); + + it('should handle errors when processing tools with circular references', async () => { + const circularTool = { + title: 'Circular Tool', + filters: { + language: 'JavaScript', + technology: ['Node.js'] + }, + links: { repoUrl: 'https://github.com/asyncapi/circular-tool' } + }; + circularTool.circular = circularTool; + + const automatedTools = { + category1: { + description: 'Category 1', + toolsList: [circularTool] + } + }; + + try { + await combineTools(automatedTools, {}, toolsPath, tagsPath); + } catch (err) { + expect(err.message).toContain('Converting circular structure to JSON'); + } + }); + + it('should throw an error when invalid manualTools data is passed', async () => { + const invalidManualTools = { + category1: { + toolsList: [{ title: 'Invalid Tool' }] + } + }; + + try { + await combineTools(automatedTools, invalidManualTools, toolsPath, tagsPath); + } catch (err) { + expect(err.message).toBe('Error processing tool: Cannot read property \'language\' of undefined'); + } + }); }); From 014fdb67d4dbe9eb0ba15c1c9f28562b80540cdd Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 30 Sep 2024 13:25:21 +0530 Subject: [PATCH 19/44] fixures --- tests/fixtures/combineToolsData.js | 100 +++++++++++++++++++++++++++++ tests/tools/combine-tools.test.js | 96 ++------------------------- 2 files changed, 106 insertions(+), 90 deletions(-) create mode 100644 tests/fixtures/combineToolsData.js diff --git a/tests/fixtures/combineToolsData.js b/tests/fixtures/combineToolsData.js new file mode 100644 index 00000000000..e96c025370b --- /dev/null +++ b/tests/fixtures/combineToolsData.js @@ -0,0 +1,100 @@ +const expectedDataT1 = { + languages: [ + { + name: 'JavaScript', + color: 'bg-[#57f281]', + borderColor: 'border-[#37f069]' + }, + { + name: 'Python', + color: 'bg-[#3572A5]', + borderColor: 'border-[#3572A5]' + } + ], + technologies: [ + { + name: 'Node.js', + color: 'bg-[#61d0f2]', + borderColor: 'border-[#40ccf7]' + }, + { + name: 'Flask', + color: 'bg-[#000000]', + borderColor: 'border-[#FFFFFF]' + } + ] +}; + +const manualToolsWithMissingData = [ + { + title: 'Tool C', + filters: {}, + links: { repoUrl: 'https://github.com/asyncapi/tool-c' } + } +]; + +const manualToolsToSort = { + category1: { + description: 'Sample Category', + toolsList: [ + { + title: 'Tool Z', + filters: { language: 'JavaScript' }, + links: { repoUrl: 'https://github.com/asyncapi/tool-z' } + }, + { + title: 'Tool A', + filters: { language: 'Python' }, + links: { repoUrl: 'https://github.com/asyncapi/tool-a' } + } + ] + } +}; + +const toolWithMultipleLanguages = { + title: 'Multi-Language Tool', + filters: { + language: ['JavaScript', 'Python', 'NewLanguage'], + technology: ['Node.js'] + }, + links: { repoUrl: 'https://github.com/example/multi-language-tool' } +}; + +const automatedToolsT5 = { + 'category1': { + description: 'Category 1 Description', + toolsList: [toolWithMultipleLanguages] + } +}; + +const invalidToolT4 = { title: 'Invalid Tool' }; + +const automatedToolsT4 = { + 'category1': { + description: 'Category 1 Description', + toolsList: [] + } +}; +const manualToolsT4 = { + 'category1': { + toolsList: [invalidToolT4] + } +}; + +const toolWithNewTagsT6 = { + title: 'New Tags Tool', + filters: { + language: 'NewLanguage', + technology: ['NewTechnology'] + }, + links: { repoUrl: 'https://github.com/example/new-tags-tool' } + }; + + const automatedToolsT6 = { + 'category1': { + description: 'Category 1 Description', + toolsList: [toolWithNewTagsT6] + } + }; + +module.exports = { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6 } \ No newline at end of file diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 89cf0460755..5bbe104b536 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -1,6 +1,7 @@ const fs = require('fs'); const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); +const { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6 } = require('../fixtures/combineToolsData') jest.mock('ajv', () => { return jest.fn().mockImplementation(() => ({ @@ -62,36 +63,10 @@ describe('combineTools function', () => { const tagsData = readJSON(tagsPath); expect(tagsData).toHaveProperty('languages'); expect(tagsData).toHaveProperty('technologies'); - expect(tagsData.languages).toContainEqual({ - name: 'JavaScript', - color: 'bg-[#57f281]', - borderColor: 'border-[#37f069]' - }); - expect(tagsData.languages).toContainEqual({ - name: 'Python', - color: 'bg-[#3572A5]', - borderColor: 'border-[#3572A5]' - }); - expect(tagsData.technologies).toContainEqual({ - name: 'Node.js', - color: 'bg-[#61d0f2]', - borderColor: 'border-[#40ccf7]' - }); - expect(tagsData.technologies).toContainEqual({ - name: 'Flask', - color: 'bg-[#000000]', - borderColor: 'border-[#FFFFFF]' - }); + expect(tagsData).toEqual(expectedDataT1) }); it('should handle tools with missing language or technology', async () => { - const manualToolsWithMissingData = [ - { - title: 'Tool C', - filters: {}, - links: { repoUrl: 'https://github.com/asyncapi/tool-c' } - } - ]; await combineTools({}, manualToolsWithMissingData, toolsPath, tagsPath); @@ -100,23 +75,6 @@ describe('combineTools function', () => { }); it('should sort tools alphabetically by title', async () => { - const manualToolsToSort = { - category1: { - description: 'Sample Category', - toolsList: [ - { - title: 'Tool Z', - filters: { language: 'JavaScript' }, - links: { repoUrl: 'https://github.com/asyncapi/tool-z' } - }, - { - title: 'Tool A', - filters: { language: 'Python' }, - links: { repoUrl: 'https://github.com/asyncapi/tool-a' } - } - ] - } - }; await combineTools(manualToolsToSort, {}, toolsPath, tagsPath); @@ -126,22 +84,10 @@ describe('combineTools function', () => { }); it('should log validation errors to console.error', async () => { - let consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => { }); - const invalidTool = { title: 'Invalid Tool' }; - const automatedTools = { - 'category1': { - description: 'Category 1 Description', - toolsList: [] - } - }; - const manualTools = { - 'category1': { - toolsList: [invalidTool] - } - }; + let consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => { }); - await combineTools(automatedTools, manualTools, toolsPath, tagsPath); + await combineTools(automatedToolsT4, manualToolsT4, toolsPath, tagsPath); const errorCalls = console.error.mock.calls; @@ -157,23 +103,8 @@ describe('combineTools function', () => { }); it('should handle tools with multiple languages, including new ones', async () => { - const toolWithMultipleLanguages = { - title: 'Multi-Language Tool', - filters: { - language: ['JavaScript', 'Python', 'NewLanguage'], - technology: ['Node.js'] - }, - links: { repoUrl: 'https://github.com/example/multi-language-tool' } - }; - const automatedTools = { - 'category1': { - description: 'Category 1 Description', - toolsList: [toolWithMultipleLanguages] - } - }; - - await combineTools(automatedTools, {}, toolsPath, tagsPath); + await combineTools(automatedToolsT5, {}, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); const tool = combinedTools.category1.toolsList[0]; @@ -188,23 +119,8 @@ describe('combineTools function', () => { }); it('should add a new language and technology when not found in the existing lists', async () => { - const toolWithNewTags = { - title: 'New Tags Tool', - filters: { - language: 'NewLanguage', - technology: ['NewTechnology'] - }, - links: { repoUrl: 'https://github.com/example/new-tags-tool' } - }; - const automatedTools = { - 'category1': { - description: 'Category 1 Description', - toolsList: [toolWithNewTags] - } - }; - - await combineTools(automatedTools, {}, toolsPath, tagsPath); + await combineTools(automatedToolsT6, {}, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); const tool = combinedTools.category1.toolsList[0]; From e74251e690ebabd6c768d098871052544bf29ea5 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 30 Sep 2024 13:31:51 +0530 Subject: [PATCH 20/44] fixture update --- tests/fixtures/combineToolsData.js | 62 +++++++++++++++++++++++++++- tests/tools/combine-tools.test.js | 65 ++---------------------------- 2 files changed, 65 insertions(+), 62 deletions(-) diff --git a/tests/fixtures/combineToolsData.js b/tests/fixtures/combineToolsData.js index e96c025370b..9c3a3e1eb43 100644 --- a/tests/fixtures/combineToolsData.js +++ b/tests/fixtures/combineToolsData.js @@ -97,4 +97,64 @@ const toolWithNewTagsT6 = { } }; -module.exports = { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6 } \ No newline at end of file + const toolWithNewLanguageT7 = { + title: 'New Language Tool', + filters: { + language: 'Go', + technology: ['Node.js'] + }, + links: { repoUrl: 'https://github.com/example/new-language-tool' } + }; + + const automatedToolsT7 = { + 'category1': { + description: 'Category 1 Description', + toolsList: [toolWithNewLanguageT7] + } + }; + + const validToolT8 = { + title: 'Valid Tool', + filters: { + language: 'JavaScript', + technology: ['Node.js'] + }, + links: { repoUrl: 'https://github.com/asyncapi/valid-tool' } + }; + + const automatedToolsT8 = { + category1: { + description: 'Category 1 Description', + toolsList: [] + } + }; + + const manualToolsT8 = { + category1: { + toolsList: [validToolT8] + } + }; + + const toolWithoutRepoUrlT9 = { + title: 'Tool Without Repo', + filters: { + language: 'Python', + technology: ['Flask'] + }, + links: {} + }; + + const automatedToolsT9 = { + category1: { + description: 'Category 1 Description', + toolsList: [] + } + }; + + const manualToolsT9 = { + category1: { + toolsList: [toolWithoutRepoUrlT9] + } + }; + +module.exports = { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6, automatedToolsT7, automatedToolsT8, manualToolsT8, automatedToolsT9, manualToolsT9 } \ No newline at end of file diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 5bbe104b536..52ad58b4aaa 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -1,7 +1,7 @@ const fs = require('fs'); const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); -const { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6 } = require('../fixtures/combineToolsData') +const { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6, automatedToolsT7, automatedToolsT8, manualToolsT8, automatedToolsT9, manualToolsT9 } = require('../fixtures/combineToolsData') jest.mock('ajv', () => { return jest.fn().mockImplementation(() => ({ @@ -145,23 +145,8 @@ describe('combineTools function', () => { }); it('should add a new language when it is not found in the existing languages list', async () => { - const toolWithNewLanguage = { - title: 'New Language Tool', - filters: { - language: 'Go', - technology: ['Node.js'] - }, - links: { repoUrl: 'https://github.com/example/new-language-tool' } - }; - - const automatedTools = { - 'category1': { - description: 'Category 1 Description', - toolsList: [toolWithNewLanguage] - } - }; - await combineTools(automatedTools, {}, toolsPath, tagsPath); + await combineTools(automatedToolsT7, {}, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); const tool = combinedTools.category1.toolsList[0]; @@ -178,29 +163,8 @@ describe('combineTools function', () => { }); it('should handle valid tool objects', async () => { - const validTool = { - title: 'Valid Tool', - filters: { - language: 'JavaScript', - technology: ['Node.js'] - }, - links: { repoUrl: 'https://github.com/asyncapi/valid-tool' } - }; - - const automatedTools = { - category1: { - description: 'Category 1 Description', - toolsList: [] - } - }; - const manualTools = { - category1: { - toolsList: [validTool] - } - }; - - await combineTools(automatedTools, manualTools, toolsPath, tagsPath); + await combineTools(automatedToolsT8, manualToolsT8, toolsPath, tagsPath); const tagsData = readJSON(tagsPath); @@ -217,29 +181,8 @@ describe('combineTools function', () => { }); it('should handle tool objects without repoUrl', async () => { - const toolWithoutRepoUrl = { - title: 'Tool Without Repo', - filters: { - language: 'Python', - technology: ['Flask'] - }, - links: {} - }; - const automatedTools = { - category1: { - description: 'Category 1 Description', - toolsList: [] - } - }; - - const manualTools = { - category1: { - toolsList: [toolWithoutRepoUrl] - } - }; - - await combineTools(automatedTools, manualTools, toolsPath, tagsPath); + await combineTools(automatedToolsT9, manualToolsT9, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); const tool = combinedTools.category1.toolsList[0]; From 07a7dc3838a9c9607d0ae424751086f495076268 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 30 Sep 2024 13:38:58 +0530 Subject: [PATCH 21/44] fixutures again --- tests/fixtures/combineToolsData.js | 117 +++++++++++++++++++---------- tests/tools/combine-tools.test.js | 48 ++---------- 2 files changed, 85 insertions(+), 80 deletions(-) diff --git a/tests/fixtures/combineToolsData.js b/tests/fixtures/combineToolsData.js index 9c3a3e1eb43..0dce8a0e492 100644 --- a/tests/fixtures/combineToolsData.js +++ b/tests/fixtures/combineToolsData.js @@ -84,77 +84,118 @@ const manualToolsT4 = { const toolWithNewTagsT6 = { title: 'New Tags Tool', filters: { - language: 'NewLanguage', - technology: ['NewTechnology'] + language: 'NewLanguage', + technology: ['NewTechnology'] }, links: { repoUrl: 'https://github.com/example/new-tags-tool' } - }; +}; - const automatedToolsT6 = { +const automatedToolsT6 = { 'category1': { - description: 'Category 1 Description', - toolsList: [toolWithNewTagsT6] + description: 'Category 1 Description', + toolsList: [toolWithNewTagsT6] } - }; +}; - const toolWithNewLanguageT7 = { +const toolWithNewLanguageT7 = { title: 'New Language Tool', filters: { - language: 'Go', - technology: ['Node.js'] + language: 'Go', + technology: ['Node.js'] }, links: { repoUrl: 'https://github.com/example/new-language-tool' } - }; +}; - const automatedToolsT7 = { +const automatedToolsT7 = { 'category1': { - description: 'Category 1 Description', - toolsList: [toolWithNewLanguageT7] + description: 'Category 1 Description', + toolsList: [toolWithNewLanguageT7] } - }; +}; - const validToolT8 = { +const validToolT8 = { title: 'Valid Tool', filters: { - language: 'JavaScript', - technology: ['Node.js'] + language: 'JavaScript', + technology: ['Node.js'] }, links: { repoUrl: 'https://github.com/asyncapi/valid-tool' } - }; +}; - const automatedToolsT8 = { +const automatedToolsT8 = { category1: { - description: 'Category 1 Description', - toolsList: [] + description: 'Category 1 Description', + toolsList: [] } - }; +}; - const manualToolsT8 = { +const manualToolsT8 = { category1: { - toolsList: [validToolT8] + toolsList: [validToolT8] } - }; +}; - const toolWithoutRepoUrlT9 = { +const toolWithoutRepoUrlT9 = { title: 'Tool Without Repo', filters: { - language: 'Python', - technology: ['Flask'] + language: 'Python', + technology: ['Flask'] }, links: {} - }; +}; + +const automatedToolsT9 = { + category1: { + description: 'Category 1 Description', + toolsList: [] + } +}; + +const manualToolsT9 = { + category1: { + toolsList: [toolWithoutRepoUrlT9] + } +}; + +const invalidAutomatedToolsT10 = { + invalidCategory: { + description: 'Invalid Category Description', + toolsList: [] + } +}; + +const manualToolsWithInvalidURLT11 = { + category1: { + toolsList: [ + { + title: 'Tool with Invalid URL', + filters: { language: 'JavaScript' }, + links: { repoUrl: 'invalid-url' } + } + ] + } +}; - const automatedToolsT9 = { +const circularTool = { + title: 'Circular Tool', + filters: { + language: 'JavaScript', + technology: ['Node.js'] + }, + links: { repoUrl: 'https://github.com/asyncapi/circular-tool' } +}; + +const automatedToolsT12 = { category1: { - description: 'Category 1 Description', - toolsList: [] + description: 'Category 1', + toolsList: [circularTool] } - }; +}; - const manualToolsT9 = { +const invalidManualToolsT13 = { category1: { - toolsList: [toolWithoutRepoUrlT9] + toolsList: [{ title: 'Invalid Tool' }] } - }; +}; -module.exports = { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6, automatedToolsT7, automatedToolsT8, manualToolsT8, automatedToolsT9, manualToolsT9 } \ No newline at end of file +module.exports = { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6, automatedToolsT7, automatedToolsT8, manualToolsT8, automatedToolsT9, manualToolsT9, invalidManualToolsT13, circularTool, automatedToolsT12, invalidAutomatedToolsT10, manualToolsWithInvalidURLT11 } \ No newline at end of file diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 52ad58b4aaa..bb4712dfc28 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -1,7 +1,7 @@ const fs = require('fs'); const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); -const { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6, automatedToolsT7, automatedToolsT8, manualToolsT8, automatedToolsT9, manualToolsT9 } = require('../fixtures/combineToolsData') +const { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6, automatedToolsT7, automatedToolsT8, manualToolsT8, automatedToolsT9, manualToolsT9, invalidManualToolsT13, automatedToolsT12, invalidAutomatedToolsT10, manualToolsWithInvalidURLT11, circularTool } = require('../fixtures/combineToolsData') jest.mock('ajv', () => { return jest.fn().mockImplementation(() => ({ @@ -201,74 +201,38 @@ describe('combineTools function', () => { }); it('should throw an error when there is an invalid category', async () => { - const invalidAutomatedTools = { - invalidCategory: { - description: 'Invalid Category Description', - toolsList: [] - } - }; try { - await combineTools(invalidAutomatedTools, manualTools, toolsPath, tagsPath); + await combineTools(invalidAutomatedToolsT10, manualTools, toolsPath, tagsPath); } catch (err) { expect(err.message).toContain('Error combining tools'); } }); it('should throw an error when URL parsing fails', async () => { - const manualToolsWithInvalidURL = { - category1: { - toolsList: [ - { - title: 'Tool with Invalid URL', - filters: { language: 'JavaScript' }, - links: { repoUrl: 'invalid-url' } - } - ] - } - }; try { - await combineTools(automatedTools, manualToolsWithInvalidURL, toolsPath, tagsPath); + await combineTools(automatedTools, manualToolsWithInvalidURLT11, toolsPath, tagsPath); } catch (err) { expect(err.message).toContain('Invalid URL'); } }); it('should handle errors when processing tools with circular references', async () => { - const circularTool = { - title: 'Circular Tool', - filters: { - language: 'JavaScript', - technology: ['Node.js'] - }, - links: { repoUrl: 'https://github.com/asyncapi/circular-tool' } - }; - circularTool.circular = circularTool; - const automatedTools = { - category1: { - description: 'Category 1', - toolsList: [circularTool] - } - }; + circularTool.circular = circularTool; try { - await combineTools(automatedTools, {}, toolsPath, tagsPath); + await combineTools(automatedToolsT12, {}, toolsPath, tagsPath); } catch (err) { expect(err.message).toContain('Converting circular structure to JSON'); } }); it('should throw an error when invalid manualTools data is passed', async () => { - const invalidManualTools = { - category1: { - toolsList: [{ title: 'Invalid Tool' }] - } - }; try { - await combineTools(automatedTools, invalidManualTools, toolsPath, tagsPath); + await combineTools(automatedTools, invalidManualToolsT13, toolsPath, tagsPath); } catch (err) { expect(err.message).toBe('Error processing tool: Cannot read property \'language\' of undefined'); } From a78dfa1729472b68ce894cbf1717afdad3aacd00 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 30 Sep 2024 13:45:10 +0530 Subject: [PATCH 22/44] idjwqf --- tests/fixtures/combineToolsData.js | 20 +++++++++++++++++++- tests/tools/combine-tools.test.js | 20 +++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/combineToolsData.js b/tests/fixtures/combineToolsData.js index 0dce8a0e492..c4a0021cc42 100644 --- a/tests/fixtures/combineToolsData.js +++ b/tests/fixtures/combineToolsData.js @@ -198,4 +198,22 @@ const invalidManualToolsT13 = { } }; -module.exports = { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6, automatedToolsT7, automatedToolsT8, manualToolsT8, automatedToolsT9, manualToolsT9, invalidManualToolsT13, circularTool, automatedToolsT12, invalidAutomatedToolsT10, manualToolsWithInvalidURLT11 } \ No newline at end of file +module.exports = { + expectedDataT1, + manualToolsWithMissingData, + manualToolsToSort, + automatedToolsT5, + automatedToolsT4, + manualToolsT4, + automatedToolsT6, + automatedToolsT7, + automatedToolsT8, + manualToolsT8, + automatedToolsT9, + manualToolsT9, + invalidManualToolsT13, + circularTool, + automatedToolsT12, + invalidAutomatedToolsT10, + manualToolsWithInvalidURLT11 +} \ No newline at end of file diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index bb4712dfc28..f3abca4a5d9 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -1,7 +1,25 @@ const fs = require('fs'); const path = require('path'); const { combineTools } = require('../../scripts/tools/combine-tools'); -const { expectedDataT1, manualToolsWithMissingData, manualToolsToSort, automatedToolsT5, automatedToolsT4, manualToolsT4, automatedToolsT6, automatedToolsT7, automatedToolsT8, manualToolsT8, automatedToolsT9, manualToolsT9, invalidManualToolsT13, automatedToolsT12, invalidAutomatedToolsT10, manualToolsWithInvalidURLT11, circularTool } = require('../fixtures/combineToolsData') +const { + expectedDataT1, + manualToolsWithMissingData, + manualToolsToSort, + automatedToolsT5, + automatedToolsT4, + manualToolsT4, + automatedToolsT6, + automatedToolsT7, + automatedToolsT8, + manualToolsT8, + automatedToolsT9, + manualToolsT9, + invalidManualToolsT13, + automatedToolsT12, + invalidAutomatedToolsT10, + manualToolsWithInvalidURLT11, + circularTool +} = require('../fixtures/combineToolsData') jest.mock('ajv', () => { return jest.fn().mockImplementation(() => ({ From 57f4dc3df6cafeb9348add5121d223df22b4dcff Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 4 Oct 2024 11:14:20 +0530 Subject: [PATCH 23/44] fwqefqe --- tests/tools/combine-tools.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index f3abca4a5d9..d2c1345a670 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -255,4 +255,5 @@ describe('combineTools function', () => { expect(err.message).toBe('Error processing tool: Cannot read property \'language\' of undefined'); } }); + }); From 0f9052e70e55ec2a227c4260a0c7b45f0d0b72e3 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 4 Oct 2024 12:55:17 +0530 Subject: [PATCH 24/44] tests updated --- scripts/tools/combine-tools.js | 3 --- tests/fixtures/combineToolsData.js | 7 ------- tests/tools/combine-tools.test.js | 25 +++++++++++++------------ 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/scripts/tools/combine-tools.js b/scripts/tools/combine-tools.js index 2fd0ef70d1c..6cd1d51ef9c 100644 --- a/scripts/tools/combine-tools.js +++ b/scripts/tools/combine-tools.js @@ -6,7 +6,6 @@ const schema = require("./tools-schema.json"); const Ajv = require("ajv") const addFormats = require("ajv-formats") const Fuse = require("fuse.js"); -const { error } = require("console"); const ajv = new Ajv() addFormats(ajv, ["uri"]) const validate = ajv.compile(schema) @@ -142,8 +141,6 @@ const combineTools = async (automatedTools, manualTools, toolsPath, tagsPath) => } catch (err) { throw new Error(`Error combining tools: ${err}`); } - fs.writeFileSync(toolsPath,JSON.stringify(finalTools)); - fs.writeFileSync(tagsPath,JSON.stringify({ languages: languageList, technologies: technologyList }),) } module.exports = { combineTools } \ No newline at end of file diff --git a/tests/fixtures/combineToolsData.js b/tests/fixtures/combineToolsData.js index c4a0021cc42..30ef6102979 100644 --- a/tests/fixtures/combineToolsData.js +++ b/tests/fixtures/combineToolsData.js @@ -192,12 +192,6 @@ const automatedToolsT12 = { } }; -const invalidManualToolsT13 = { - category1: { - toolsList: [{ title: 'Invalid Tool' }] - } -}; - module.exports = { expectedDataT1, manualToolsWithMissingData, @@ -211,7 +205,6 @@ module.exports = { manualToolsT8, automatedToolsT9, manualToolsT9, - invalidManualToolsT13, circularTool, automatedToolsT12, invalidAutomatedToolsT10, diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index d2c1345a670..78fee5441b2 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -14,12 +14,11 @@ const { manualToolsT8, automatedToolsT9, manualToolsT9, - invalidManualToolsT13, automatedToolsT12, invalidAutomatedToolsT10, manualToolsWithInvalidURLT11, circularTool -} = require('../fixtures/combineToolsData') +} = require('../fixtures/combineToolsData'); jest.mock('ajv', () => { return jest.fn().mockImplementation(() => ({ @@ -209,51 +208,53 @@ describe('combineTools function', () => { }); it('should throw an error when fs.writeFileSync fails', async () => { + let error; let invalidPath = "this/is/not/valid" try { await combineTools(automatedTools, manualTools, invalidPath, invalidPath); } catch (err) { + error = err; expect(err.message).toMatch(/ENOENT|EACCES/); } + expect(error).toBeDefined(); }); it('should throw an error when there is an invalid category', async () => { + let error; try { await combineTools(invalidAutomatedToolsT10, manualTools, toolsPath, tagsPath); } catch (err) { + error = err; expect(err.message).toContain('Error combining tools'); } + expect(error).toBeDefined(); }); it('should throw an error when URL parsing fails', async () => { + let error; try { await combineTools(automatedTools, manualToolsWithInvalidURLT11, toolsPath, tagsPath); } catch (err) { + error = err; expect(err.message).toContain('Invalid URL'); } + expect(error).toBeDefined(); }); it('should handle errors when processing tools with circular references', async () => { - + let error; circularTool.circular = circularTool; try { await combineTools(automatedToolsT12, {}, toolsPath, tagsPath); } catch (err) { + error = err; expect(err.message).toContain('Converting circular structure to JSON'); } - }); - - it('should throw an error when invalid manualTools data is passed', async () => { - - try { - await combineTools(automatedTools, invalidManualToolsT13, toolsPath, tagsPath); - } catch (err) { - expect(err.message).toBe('Error processing tool: Cannot read property \'language\' of undefined'); - } + expect(error).toBeDefined(); }); }); From f95ecce6da7f5dd325d728bdf05c28c3c32f485a Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sun, 13 Oct 2024 22:27:04 +0530 Subject: [PATCH 25/44] buildtools update --- scripts/build-tools.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/build-tools.js b/scripts/build-tools.js index 04c6a05113d..1f5870ed6c0 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -5,7 +5,6 @@ const fs = require('fs'); const { resolve } = require('path'); const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPath) => { - try { let githubExtractData = await getData(); let automatedTools = await convertTools(githubExtractData); @@ -14,9 +13,8 @@ const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPa automatedToolsPath, JSON.stringify(automatedTools, null, ' ') ); - - await combineTools(automatedTools, require(manualToolsPath), toolsPath, tagsPath); + await combineTools(automatedTools, require(manualToolsPath), toolsPath, tagsPath); } catch (err) { throw new Error(`An error occurred while building tools: ${err.message}`); } @@ -32,4 +30,4 @@ if (require.main === module) { buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath); } -module.exports = { buildTools }; +module.exports = { buildTools }; \ No newline at end of file From acb1ec3b4b8b144bea632c66b4792eaee5628d34 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sun, 13 Oct 2024 22:28:56 +0530 Subject: [PATCH 26/44] add empty line at last --- scripts/build-tools.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build-tools.js b/scripts/build-tools.js index 1f5870ed6c0..84965815dcc 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -30,4 +30,4 @@ if (require.main === module) { buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath); } -module.exports = { buildTools }; \ No newline at end of file +module.exports = { buildTools }; From 5c4c19259739cdff4ffdb897482eeeeac2918a42 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Wed, 16 Oct 2024 18:59:54 +0530 Subject: [PATCH 27/44] update path --- scripts/build-tools.js | 10 +++++----- tests/build-tools.test.js | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/build-tools.js b/scripts/build-tools.js index 84965815dcc..05c9e85bcb9 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -2,7 +2,7 @@ const { getData } = require('./tools/extract-tools-github'); const { convertTools } = require('./tools/tools-object'); const { combineTools } = require('./tools/combine-tools'); const fs = require('fs'); -const { resolve } = require('path'); +const path = require('path'); const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPath) => { try { @@ -22,10 +22,10 @@ const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPa /* istanbul ignore next */ if (require.main === module) { - const automatedToolsPath = resolve(__dirname, '../config', 'tools-automated.json'); - const manualToolsPath = resolve(__dirname, '../config', 'tools-manual.json'); - const toolsPath = resolve(__dirname, '../config', 'tools.json'); - const tagsPath = resolve(__dirname, '../config', 'all-tags.json'); + const automatedToolsPath = path.join(__dirname, '../config', 'tools-automated.json'); + const manualToolsPath = path.join(__dirname, '../config', 'tools-manual.json'); + const toolsPath = path.join(__dirname, '../config', 'tools.json'); + const tagsPath = path.join(__dirname, '../config', 'all-tags.json'); buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath); } diff --git a/tests/build-tools.test.js b/tests/build-tools.test.js index 2bc4592e8e1..c8d0a029079 100644 --- a/tests/build-tools.test.js +++ b/tests/build-tools.test.js @@ -1,5 +1,5 @@ const axios = require('axios'); -const { resolve } = require('path'); +const path = require('path'); const { buildTools } = require('../scripts/build-tools'); const { tagsData, manualTools, mockConvertedData, mockExtractData } = require('../tests/fixtures/buildToolsData'); const fs = require('fs'); @@ -24,11 +24,11 @@ jest.mock('../scripts/tools/tags-color', () => ({ })); describe('buildTools', () => { - const testDir = resolve(__dirname, 'test_config'); - const toolsPath = resolve(testDir, 'tools.json'); - const tagsPath = resolve(testDir, 'all-tags.json'); - const automatedToolsPath = resolve(testDir, 'tools-automated.json'); - const manualToolsPath = resolve(testDir, 'tools-manual.json'); + const testDir = path.join(__dirname, 'test_config'); + const toolsPath = path.join(testDir, 'tools.json'); + const tagsPath = path.join(testDir, 'all-tags.json'); + const automatedToolsPath = path.join(testDir, 'tools-automated.json'); + const manualToolsPath = path.join(testDir, 'tools-manual.json'); beforeAll(() => { fs.mkdirSync(testDir, { recursive: true }); @@ -78,7 +78,7 @@ describe('buildTools', () => { it('should handle file write errors', async () => { axios.get.mockResolvedValue({ data: mockExtractData }); - const invalidPath = '/invalid_dir/tools.json'; + const invalidPath = path.join('/invalid_dir', 'tools.json'); try { await buildTools(invalidPath, manualToolsPath, toolsPath, tagsPath); From aeabab20d28b760dc3decc477c2ba9214349e93b Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 18 Oct 2024 10:53:24 +0530 Subject: [PATCH 28/44] wfq --- scripts/build-tools.js | 10 +++++----- tests/build-tools.test.js | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/build-tools.js b/scripts/build-tools.js index 05c9e85bcb9..84965815dcc 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -2,7 +2,7 @@ const { getData } = require('./tools/extract-tools-github'); const { convertTools } = require('./tools/tools-object'); const { combineTools } = require('./tools/combine-tools'); const fs = require('fs'); -const path = require('path'); +const { resolve } = require('path'); const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPath) => { try { @@ -22,10 +22,10 @@ const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPa /* istanbul ignore next */ if (require.main === module) { - const automatedToolsPath = path.join(__dirname, '../config', 'tools-automated.json'); - const manualToolsPath = path.join(__dirname, '../config', 'tools-manual.json'); - const toolsPath = path.join(__dirname, '../config', 'tools.json'); - const tagsPath = path.join(__dirname, '../config', 'all-tags.json'); + const automatedToolsPath = resolve(__dirname, '../config', 'tools-automated.json'); + const manualToolsPath = resolve(__dirname, '../config', 'tools-manual.json'); + const toolsPath = resolve(__dirname, '../config', 'tools.json'); + const tagsPath = resolve(__dirname, '../config', 'all-tags.json'); buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath); } diff --git a/tests/build-tools.test.js b/tests/build-tools.test.js index c8d0a029079..2bc4592e8e1 100644 --- a/tests/build-tools.test.js +++ b/tests/build-tools.test.js @@ -1,5 +1,5 @@ const axios = require('axios'); -const path = require('path'); +const { resolve } = require('path'); const { buildTools } = require('../scripts/build-tools'); const { tagsData, manualTools, mockConvertedData, mockExtractData } = require('../tests/fixtures/buildToolsData'); const fs = require('fs'); @@ -24,11 +24,11 @@ jest.mock('../scripts/tools/tags-color', () => ({ })); describe('buildTools', () => { - const testDir = path.join(__dirname, 'test_config'); - const toolsPath = path.join(testDir, 'tools.json'); - const tagsPath = path.join(testDir, 'all-tags.json'); - const automatedToolsPath = path.join(testDir, 'tools-automated.json'); - const manualToolsPath = path.join(testDir, 'tools-manual.json'); + const testDir = resolve(__dirname, 'test_config'); + const toolsPath = resolve(testDir, 'tools.json'); + const tagsPath = resolve(testDir, 'all-tags.json'); + const automatedToolsPath = resolve(testDir, 'tools-automated.json'); + const manualToolsPath = resolve(testDir, 'tools-manual.json'); beforeAll(() => { fs.mkdirSync(testDir, { recursive: true }); @@ -78,7 +78,7 @@ describe('buildTools', () => { it('should handle file write errors', async () => { axios.get.mockResolvedValue({ data: mockExtractData }); - const invalidPath = path.join('/invalid_dir', 'tools.json'); + const invalidPath = '/invalid_dir/tools.json'; try { await buildTools(invalidPath, manualToolsPath, toolsPath, tagsPath); From db33c88642e96598be152cb5c4bd785cd039dfbf Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 18 Oct 2024 21:28:39 +0530 Subject: [PATCH 29/44] supress logs --- tests/build-tools.test.js | 3 +++ tests/tools/combine-tools.test.js | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/build-tools.test.js b/tests/build-tools.test.js index 2bc4592e8e1..d1de02f5435 100644 --- a/tests/build-tools.test.js +++ b/tests/build-tools.test.js @@ -29,14 +29,17 @@ describe('buildTools', () => { const tagsPath = resolve(testDir, 'all-tags.json'); const automatedToolsPath = resolve(testDir, 'tools-automated.json'); const manualToolsPath = resolve(testDir, 'tools-manual.json'); + let consoleErrorMock; beforeAll(() => { fs.mkdirSync(testDir, { recursive: true }); fs.writeFileSync(manualToolsPath, JSON.stringify(manualTools)); + consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {}); }); afterAll(() => { fs.rmSync(testDir, { recursive: true, force: true }); + consoleErrorMock.mockRestore(); }); beforeEach(() => { diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 78fee5441b2..0be213a4444 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -59,16 +59,20 @@ describe('combineTools function', () => { let manualTools; let automatedTools; + let consoleErrorMock; beforeAll(() => { manualTools = readJSON(manualToolsPath); automatedTools = readJSON(automatedToolsPath); + consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {}); }); afterAll(() => { if (fs.existsSync(toolsPath)) fs.unlinkSync(toolsPath); if (fs.existsSync(tagsPath)) fs.unlinkSync(tagsPath); + + consoleErrorMock.mockRestore(); }); it('should combine tools and create correct JSON files', async () => { @@ -102,8 +106,6 @@ describe('combineTools function', () => { it('should log validation errors to console.error', async () => { - let consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => { }); - await combineTools(automatedToolsT4, manualToolsT4, toolsPath, tagsPath); const errorCalls = console.error.mock.calls; @@ -115,8 +117,6 @@ describe('combineTools function', () => { expect(fs.existsSync(toolsPath)).toBe(true); expect(fs.existsSync(tagsPath)).toBe(true); - - consoleErrorMock.mockRestore(); }); it('should handle tools with multiple languages, including new ones', async () => { @@ -256,5 +256,4 @@ describe('combineTools function', () => { } expect(error).toBeDefined(); }); - }); From 820de27e7436aa8a68267ac2480d1f46f728462a Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 18 Oct 2024 22:07:06 +0530 Subject: [PATCH 30/44] test and function update --- scripts/build-newsroom-videos.js | 8 ++++++-- scripts/build-tools.js | 6 +++++- tests/build-newsroom-videos.test.js | 16 ++++++++++++---- tests/build-tools.test.js | 17 +++++++++++++---- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/scripts/build-newsroom-videos.js b/scripts/build-newsroom-videos.js index b67ee0378cf..f8a06787bdf 100644 --- a/scripts/build-newsroom-videos.js +++ b/scripts/build-newsroom-videos.js @@ -1,9 +1,13 @@ -const { writeFileSync } = require('fs'); -const { resolve } = require('path'); +const { writeFileSync, mkdirSync, existsSync } = require('fs'); +const { resolve, dirname } = require('path'); const fetch = require('node-fetch-2'); async function buildNewsroomVideos(writePath) { try { + const dir = dirname(writePath); + if (!existsSync(dir)) { + mkdirSync(dir, { recursive: true }); + } const response = await fetch('https://youtube.googleapis.com/youtube/v3/search?' + new URLSearchParams({ key: process.env.YOUTUBE_TOKEN, part: 'snippet', diff --git a/scripts/build-tools.js b/scripts/build-tools.js index 84965815dcc..e0ade7dd39e 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -2,13 +2,17 @@ const { getData } = require('./tools/extract-tools-github'); const { convertTools } = require('./tools/tools-object'); const { combineTools } = require('./tools/combine-tools'); const fs = require('fs'); -const { resolve } = require('path'); +const { resolve, dirname } = require('path'); const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPath) => { try { let githubExtractData = await getData(); let automatedTools = await convertTools(githubExtractData); + const automatedDir = dirname(automatedToolsPath); + if (!fs.existsSync(automatedDir)) { + fs.mkdirSync(automatedDir, { recursive: true }); + } fs.writeFileSync( automatedToolsPath, JSON.stringify(automatedTools, null, ' ') diff --git a/tests/build-newsroom-videos.test.js b/tests/build-newsroom-videos.test.js index 63f57146694..704b479fa0e 100644 --- a/tests/build-newsroom-videos.test.js +++ b/tests/build-newsroom-videos.test.js @@ -1,4 +1,4 @@ -const { readFileSync, rmSync, mkdirSync } = require('fs'); +const { readFileSync, rmSync, mkdirSync, existsSync } = require('fs'); const { resolve } = require('path'); const { buildNewsroomVideos } = require('../scripts/build-newsroom-videos'); const { mockApiResponse, expectedResult } = require('./fixtures/newsroomData'); @@ -11,15 +11,19 @@ describe('buildNewsroomVideos', () => { const testFilePath = resolve(testDir, 'newsroom_videos.json'); beforeAll(() => { - mkdirSync(testDir, { recursive: true }); process.env.YOUTUBE_TOKEN = 'testkey'; }); afterAll(() => { - rmSync(testDir, { recursive: true, force: true }); + if (existsSync(testDir)) { + rmSync(testDir, { recursive: true, force: true }); + } }); beforeEach(() => { + if (!existsSync(testDir)) { + mkdirSync(testDir, { recursive: true }); + } fetch.mockClear(); }); @@ -29,6 +33,10 @@ describe('buildNewsroomVideos', () => { json: jest.fn().mockResolvedValue(mockApiResponse), }); + if (!existsSync(testDir)) { + mkdirSync(testDir, { recursive: true }); + } + const result = await buildNewsroomVideos(testFilePath); const expectedUrl = new URL('https://youtube.googleapis.com/youtube/v3/search'); @@ -41,6 +49,7 @@ describe('buildNewsroomVideos', () => { expectedUrl.searchParams.set('maxResults', '5'); expect(fetch).toHaveBeenCalledWith(expectedUrl.toString()); + const response = readFileSync(testFilePath, 'utf8'); expect(response).toEqual(expectedResult); expect(result).toEqual(expectedResult); @@ -97,5 +106,4 @@ describe('buildNewsroomVideos', () => { expect(err.message).toMatch(/ENOENT|EACCES/); } }); - }); diff --git a/tests/build-tools.test.js b/tests/build-tools.test.js index d1de02f5435..7be2e5148e8 100644 --- a/tests/build-tools.test.js +++ b/tests/build-tools.test.js @@ -32,13 +32,19 @@ describe('buildTools', () => { let consoleErrorMock; beforeAll(() => { - fs.mkdirSync(testDir, { recursive: true }); - fs.writeFileSync(manualToolsPath, JSON.stringify(manualTools)); + if (!fs.existsSync(testDir)) { + fs.mkdirSync(testDir, { recursive: true }); + } + if (!fs.existsSync(manualToolsPath)) { + fs.writeFileSync(manualToolsPath, JSON.stringify(manualTools)); + } consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {}); }); afterAll(() => { - fs.rmSync(testDir, { recursive: true, force: true }); + if (fs.existsSync(testDir)) { + fs.rmSync(testDir, { recursive: true, force: true }); + } consoleErrorMock.mockRestore(); }); @@ -49,6 +55,10 @@ describe('buildTools', () => { it('should extract, convert, combine tools, and write to file', async () => { axios.get.mockResolvedValue({ data: mockExtractData }); + if (!fs.existsSync(testDir)) { + fs.mkdirSync(testDir, { recursive: true }); + } + await buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath); const automatedToolsContent = JSON.parse(fs.readFileSync(automatedToolsPath, 'utf8')); @@ -65,7 +75,6 @@ describe('buildTools', () => { expect(combinedToolsContent["Category2"].description).toEqual(mockConvertedData["Category2"].description); expect(tagsContent).toEqual(tagsData); - }); it('should handle getData error', async () => { From b16fca90f8857ba7c6c80eac371e059623b952fd Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 18 Oct 2024 22:07:35 +0530 Subject: [PATCH 31/44] commit to re run the workflow --- scripts/build-tools.js | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/build-tools.js b/scripts/build-tools.js index e0ade7dd39e..d3e4d6c1089 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -8,6 +8,7 @@ const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPa try { let githubExtractData = await getData(); let automatedTools = await convertTools(githubExtractData); + const automatedDir = dirname(automatedToolsPath); if (!fs.existsSync(automatedDir)) { From 995b9bdafe5224f52e88c9f34d7b3a0a00f361b0 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 18 Oct 2024 22:10:27 +0530 Subject: [PATCH 32/44] commit to re run the workflow again --- tests/tools/combine-tools.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 0be213a4444..90cc9e80f8e 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -256,4 +256,5 @@ describe('combineTools function', () => { } expect(error).toBeDefined(); }); + }); From bd6424da5890f9764b148614086109eccf05b038 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 19 Oct 2024 11:06:56 +0530 Subject: [PATCH 33/44] added retry mechanicasm for enoent errors --- scripts/build-newsroom-videos.js | 24 +++++++++++++++++++++--- scripts/build-tools.js | 23 +++++++++++++++++++---- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/scripts/build-newsroom-videos.js b/scripts/build-newsroom-videos.js index f8a06787bdf..f4cf8306692 100644 --- a/scripts/build-newsroom-videos.js +++ b/scripts/build-newsroom-videos.js @@ -5,9 +5,11 @@ const fetch = require('node-fetch-2'); async function buildNewsroomVideos(writePath) { try { const dir = dirname(writePath); + if (!existsSync(dir)) { mkdirSync(dir, { recursive: true }); } + const response = await fetch('https://youtube.googleapis.com/youtube/v3/search?' + new URLSearchParams({ key: process.env.YOUTUBE_TOKEN, part: 'snippet', @@ -23,7 +25,6 @@ async function buildNewsroomVideos(writePath) { } const data = await response.json(); - console.log(data) if (!data.items || !Array.isArray(data.items)) { throw new Error('Invalid data structure received from YouTube API'); @@ -39,7 +40,7 @@ async function buildNewsroomVideos(writePath) { const videoData = JSON.stringify(videoDataItems, null, ' '); console.log('The following are the Newsroom Youtube videos: ', videoData); - writeFileSync(writePath, videoData); + await retryWriteFile(writePath, videoData); return videoData; } catch (err) { @@ -47,9 +48,26 @@ async function buildNewsroomVideos(writePath) { } } +async function retryWriteFile(filePath, data, retries = 3, delay = 1000) { + for (let attempt = 0; attempt < retries; attempt++) { + try { + writeFileSync(filePath, data); + console.log(`File written successfully to ${filePath}`); + break; + } catch (err) { + if (err.code === 'ENOENT') { + console.error(`ENOENT error on attempt ${attempt + 1}. Retrying in ${delay}ms...`); + await new Promise((resolve) => setTimeout(resolve, delay)); + } else { + throw err; + } + } + } +} + /* istanbul ignore next */ if (require.main === module) { - buildNewsroomVideos(resolve(__dirname, '../config', 'newsroom_videos.json')) + buildNewsroomVideos(resolve(__dirname, '../config', 'newsroom_videos.json')); } module.exports = { buildNewsroomVideos }; diff --git a/scripts/build-tools.js b/scripts/build-tools.js index d3e4d6c1089..2b7c47768f7 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -14,10 +14,8 @@ const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPa if (!fs.existsSync(automatedDir)) { fs.mkdirSync(automatedDir, { recursive: true }); } - fs.writeFileSync( - automatedToolsPath, - JSON.stringify(automatedTools, null, ' ') - ); + + await retryWriteFile(automatedToolsPath, JSON.stringify(automatedTools, null, ' ')); await combineTools(automatedTools, require(manualToolsPath), toolsPath, tagsPath); } catch (err) { @@ -25,6 +23,23 @@ const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPa } }; +async function retryWriteFile(filePath, data, retries = 3, delay = 1000) { + for (let attempt = 0; attempt < retries; attempt++) { + try { + fs.writeFileSync(filePath, data); + console.log(`File written successfully to ${filePath}`); + break; + } catch (err) { + if (err.code === 'ENOENT') { + console.error(`ENOENT error on attempt ${attempt + 1}. Retrying in ${delay}ms...`); + await new Promise((resolve) => setTimeout(resolve, delay)); + } else { + throw err; + } + } + } +} + /* istanbul ignore next */ if (require.main === module) { const automatedToolsPath = resolve(__dirname, '../config', 'tools-automated.json'); From 233efdd82636c68fe445cfe10e378b82356951bf Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 19 Oct 2024 18:17:35 +0530 Subject: [PATCH 34/44] use fsextra --- package-lock.json | 124 ++++++++-------------------- package.json | 1 + scripts/build-newsroom-videos.js | 32 ++----- scripts/build-tools.js | 29 +------ tests/build-newsroom-videos.test.js | 15 +--- tests/build-tools.test.js | 19 ++--- 6 files changed, 53 insertions(+), 167 deletions(-) diff --git a/package-lock.json b/package-lock.json index bea2b1cc43e..3e06c5cffdb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "clsx": "^2.1.0", "cssnano": "^6.0.3", "dotenv": "^16.4.4", + "fs-extra": "^11.2.0", "fuse.js": "^7.0.0", "googleapis": "^133.0.0", "gray-matter": "^4.0.3", @@ -4697,20 +4698,6 @@ "unstorage": "1.9.0" } }, - "node_modules/@netlify/ipx/node_modules/fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "dev": true, - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, "node_modules/@netlify/ipx/node_modules/node-fetch": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", @@ -4787,6 +4774,21 @@ "node": ">=14.0.0" } }, + "node_modules/@netlify/plugin-nextjs/node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@netlify/plugin-nextjs/node_modules/node-fetch": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", @@ -6253,20 +6255,6 @@ "storybook": "^8.2.9" } }, - "node_modules/@storybook/addon-docs/node_modules/fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "dev": true, - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, "node_modules/@storybook/addon-essentials": { "version": "8.2.9", "resolved": "https://registry.npmjs.org/@storybook/addon-essentials/-/addon-essentials-8.2.9.tgz", @@ -6526,20 +6514,6 @@ "undici-types": "~5.26.4" } }, - "node_modules/@storybook/builder-webpack5/node_modules/fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "dev": true, - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, "node_modules/@storybook/codemod": { "version": "8.2.9", "resolved": "https://registry.npmjs.org/@storybook/codemod/-/codemod-8.2.9.tgz", @@ -6829,20 +6803,6 @@ "undici-types": "~5.26.4" } }, - "node_modules/@storybook/nextjs/node_modules/fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "dev": true, - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, "node_modules/@storybook/preset-react-webpack": { "version": "8.2.9", "resolved": "https://registry.npmjs.org/@storybook/preset-react-webpack/-/preset-react-webpack-8.2.9.tgz", @@ -6890,20 +6850,6 @@ "undici-types": "~5.26.4" } }, - "node_modules/@storybook/preset-react-webpack/node_modules/fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "dev": true, - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, "node_modules/@storybook/preview-api": { "version": "8.2.9", "resolved": "https://registry.npmjs.org/@storybook/preview-api/-/preview-api-8.2.9.tgz", @@ -14227,6 +14173,21 @@ "concat-map": "0.0.1" } }, + "node_modules/fork-ts-checker-webpack-plugin/node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/fork-ts-checker-webpack-plugin/node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -14339,17 +14300,17 @@ "dev": true }, "node_modules/fs-extra": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", - "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", - "dev": true, + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", + "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", + "license": "MIT", "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" }, "engines": { - "node": ">=12" + "node": ">=14.14" } }, "node_modules/fs-minipass": { @@ -27097,19 +27058,6 @@ "node": ">= 6" } }, - "node_modules/storybook/node_modules/fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, "node_modules/storybook/node_modules/globby": { "version": "14.0.2", "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.2.tgz", diff --git a/package.json b/package.json index 04ba37b586e..aab6109d134 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "clsx": "^2.1.0", "cssnano": "^6.0.3", "dotenv": "^16.4.4", + "fs-extra": "^11.2.0", "fuse.js": "^7.0.0", "googleapis": "^133.0.0", "gray-matter": "^4.0.3", diff --git a/scripts/build-newsroom-videos.js b/scripts/build-newsroom-videos.js index f4cf8306692..383927765d3 100644 --- a/scripts/build-newsroom-videos.js +++ b/scripts/build-newsroom-videos.js @@ -1,15 +1,9 @@ -const { writeFileSync, mkdirSync, existsSync } = require('fs'); -const { resolve, dirname } = require('path'); +const { writeFileSync } = require('fs-extra'); +const { resolve } = require('path'); const fetch = require('node-fetch-2'); async function buildNewsroomVideos(writePath) { try { - const dir = dirname(writePath); - - if (!existsSync(dir)) { - mkdirSync(dir, { recursive: true }); - } - const response = await fetch('https://youtube.googleapis.com/youtube/v3/search?' + new URLSearchParams({ key: process.env.YOUTUBE_TOKEN, part: 'snippet', @@ -25,6 +19,7 @@ async function buildNewsroomVideos(writePath) { } const data = await response.json(); + console.log(data); if (!data.items || !Array.isArray(data.items)) { throw new Error('Invalid data structure received from YouTube API'); @@ -40,7 +35,7 @@ async function buildNewsroomVideos(writePath) { const videoData = JSON.stringify(videoDataItems, null, ' '); console.log('The following are the Newsroom Youtube videos: ', videoData); - await retryWriteFile(writePath, videoData); + writeFileSync(writePath, videoData); return videoData; } catch (err) { @@ -48,26 +43,9 @@ async function buildNewsroomVideos(writePath) { } } -async function retryWriteFile(filePath, data, retries = 3, delay = 1000) { - for (let attempt = 0; attempt < retries; attempt++) { - try { - writeFileSync(filePath, data); - console.log(`File written successfully to ${filePath}`); - break; - } catch (err) { - if (err.code === 'ENOENT') { - console.error(`ENOENT error on attempt ${attempt + 1}. Retrying in ${delay}ms...`); - await new Promise((resolve) => setTimeout(resolve, delay)); - } else { - throw err; - } - } - } -} - /* istanbul ignore next */ if (require.main === module) { - buildNewsroomVideos(resolve(__dirname, '../config', 'newsroom_videos.json')); + buildNewsroomVideos(resolve(__dirname, '../config', 'newsroom_videos.json')) } module.exports = { buildNewsroomVideos }; diff --git a/scripts/build-tools.js b/scripts/build-tools.js index 2b7c47768f7..c5cce74a7cb 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -1,21 +1,15 @@ const { getData } = require('./tools/extract-tools-github'); const { convertTools } = require('./tools/tools-object'); const { combineTools } = require('./tools/combine-tools'); -const fs = require('fs'); -const { resolve, dirname } = require('path'); +const fs = require('fs-extra'); +const { resolve } = require('path'); const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPath) => { try { let githubExtractData = await getData(); let automatedTools = await convertTools(githubExtractData); - - const automatedDir = dirname(automatedToolsPath); - if (!fs.existsSync(automatedDir)) { - fs.mkdirSync(automatedDir, { recursive: true }); - } - - await retryWriteFile(automatedToolsPath, JSON.stringify(automatedTools, null, ' ')); + await fs.writeFile(automatedToolsPath, JSON.stringify(automatedTools, null, ' ')); await combineTools(automatedTools, require(manualToolsPath), toolsPath, tagsPath); } catch (err) { @@ -23,23 +17,6 @@ const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPa } }; -async function retryWriteFile(filePath, data, retries = 3, delay = 1000) { - for (let attempt = 0; attempt < retries; attempt++) { - try { - fs.writeFileSync(filePath, data); - console.log(`File written successfully to ${filePath}`); - break; - } catch (err) { - if (err.code === 'ENOENT') { - console.error(`ENOENT error on attempt ${attempt + 1}. Retrying in ${delay}ms...`); - await new Promise((resolve) => setTimeout(resolve, delay)); - } else { - throw err; - } - } - } -} - /* istanbul ignore next */ if (require.main === module) { const automatedToolsPath = resolve(__dirname, '../config', 'tools-automated.json'); diff --git a/tests/build-newsroom-videos.test.js b/tests/build-newsroom-videos.test.js index 704b479fa0e..a43c55ea9cd 100644 --- a/tests/build-newsroom-videos.test.js +++ b/tests/build-newsroom-videos.test.js @@ -1,4 +1,4 @@ -const { readFileSync, rmSync, mkdirSync, existsSync } = require('fs'); +const { readFileSync, removeSync, mkdirpSync } = require('fs-extra'); const { resolve } = require('path'); const { buildNewsroomVideos } = require('../scripts/build-newsroom-videos'); const { mockApiResponse, expectedResult } = require('./fixtures/newsroomData'); @@ -11,19 +11,15 @@ describe('buildNewsroomVideos', () => { const testFilePath = resolve(testDir, 'newsroom_videos.json'); beforeAll(() => { + mkdirpSync(testDir); process.env.YOUTUBE_TOKEN = 'testkey'; }); afterAll(() => { - if (existsSync(testDir)) { - rmSync(testDir, { recursive: true, force: true }); - } + removeSync(testDir); }); beforeEach(() => { - if (!existsSync(testDir)) { - mkdirSync(testDir, { recursive: true }); - } fetch.mockClear(); }); @@ -33,10 +29,6 @@ describe('buildNewsroomVideos', () => { json: jest.fn().mockResolvedValue(mockApiResponse), }); - if (!existsSync(testDir)) { - mkdirSync(testDir, { recursive: true }); - } - const result = await buildNewsroomVideos(testFilePath); const expectedUrl = new URL('https://youtube.googleapis.com/youtube/v3/search'); @@ -49,7 +41,6 @@ describe('buildNewsroomVideos', () => { expectedUrl.searchParams.set('maxResults', '5'); expect(fetch).toHaveBeenCalledWith(expectedUrl.toString()); - const response = readFileSync(testFilePath, 'utf8'); expect(response).toEqual(expectedResult); expect(result).toEqual(expectedResult); diff --git a/tests/build-tools.test.js b/tests/build-tools.test.js index 7be2e5148e8..4377e1f298f 100644 --- a/tests/build-tools.test.js +++ b/tests/build-tools.test.js @@ -2,7 +2,7 @@ const axios = require('axios'); const { resolve } = require('path'); const { buildTools } = require('../scripts/build-tools'); const { tagsData, manualTools, mockConvertedData, mockExtractData } = require('../tests/fixtures/buildToolsData'); -const fs = require('fs'); +const fs = require('fs-extra'); jest.mock('axios'); jest.mock('../scripts/tools/categorylist', () => ({ @@ -32,19 +32,14 @@ describe('buildTools', () => { let consoleErrorMock; beforeAll(() => { - if (!fs.existsSync(testDir)) { - fs.mkdirSync(testDir, { recursive: true }); - } - if (!fs.existsSync(manualToolsPath)) { - fs.writeFileSync(manualToolsPath, JSON.stringify(manualTools)); - } consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {}); + + fs.ensureDirSync(testDir); + fs.outputFileSync(manualToolsPath, JSON.stringify(manualTools)); }); afterAll(() => { - if (fs.existsSync(testDir)) { - fs.rmSync(testDir, { recursive: true, force: true }); - } + fs.removeSync(testDir); consoleErrorMock.mockRestore(); }); @@ -55,10 +50,6 @@ describe('buildTools', () => { it('should extract, convert, combine tools, and write to file', async () => { axios.get.mockResolvedValue({ data: mockExtractData }); - if (!fs.existsSync(testDir)) { - fs.mkdirSync(testDir, { recursive: true }); - } - await buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath); const automatedToolsContent = JSON.parse(fs.readFileSync(automatedToolsPath, 'utf8')); From 4b13fc8b942d3a1d79da75cffc24dbc488352f9a Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 19 Oct 2024 18:30:16 +0530 Subject: [PATCH 35/44] update test --- scripts/build-newsroom-videos.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build-newsroom-videos.js b/scripts/build-newsroom-videos.js index 383927765d3..0cd466926aa 100644 --- a/scripts/build-newsroom-videos.js +++ b/scripts/build-newsroom-videos.js @@ -1,4 +1,4 @@ -const { writeFileSync } = require('fs-extra'); +const { writeFile } = require('fs-extra'); const { resolve } = require('path'); const fetch = require('node-fetch-2'); @@ -35,7 +35,7 @@ async function buildNewsroomVideos(writePath) { const videoData = JSON.stringify(videoDataItems, null, ' '); console.log('The following are the Newsroom Youtube videos: ', videoData); - writeFileSync(writePath, videoData); + await writeFile(writePath, videoData); return videoData; } catch (err) { From 0489f2d77263b7e2a4a8d6308a4f0486b1aebb8d Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 19 Oct 2024 18:37:27 +0530 Subject: [PATCH 36/44] fqewfewqf --- scripts/build-tools.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build-tools.js b/scripts/build-tools.js index c5cce74a7cb..8d1d031862f 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -9,7 +9,7 @@ const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPa let githubExtractData = await getData(); let automatedTools = await convertTools(githubExtractData); - await fs.writeFile(automatedToolsPath, JSON.stringify(automatedTools, null, ' ')); + fs.writeFileSync(automatedToolsPath, JSON.stringify(automatedTools, null, ' ')); await combineTools(automatedTools, require(manualToolsPath), toolsPath, tagsPath); } catch (err) { From 774da3fbf1ad90796bfed0645d0bd6b54aec8a4f Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 19 Oct 2024 18:41:01 +0530 Subject: [PATCH 37/44] fqewfewqf --- tests/tools/combine-tools.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 90cc9e80f8e..0be213a4444 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -256,5 +256,4 @@ describe('combineTools function', () => { } expect(error).toBeDefined(); }); - }); From 7c24517a4bd3a2109b4b129a9eb1885b420e395d Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 19 Oct 2024 18:56:14 +0530 Subject: [PATCH 38/44] fqwefge --- scripts/build-newsroom-videos.js | 4 ++-- scripts/build-tools.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/build-newsroom-videos.js b/scripts/build-newsroom-videos.js index 0cd466926aa..383927765d3 100644 --- a/scripts/build-newsroom-videos.js +++ b/scripts/build-newsroom-videos.js @@ -1,4 +1,4 @@ -const { writeFile } = require('fs-extra'); +const { writeFileSync } = require('fs-extra'); const { resolve } = require('path'); const fetch = require('node-fetch-2'); @@ -35,7 +35,7 @@ async function buildNewsroomVideos(writePath) { const videoData = JSON.stringify(videoDataItems, null, ' '); console.log('The following are the Newsroom Youtube videos: ', videoData); - await writeFile(writePath, videoData); + writeFileSync(writePath, videoData); return videoData; } catch (err) { diff --git a/scripts/build-tools.js b/scripts/build-tools.js index 8d1d031862f..c5cce74a7cb 100644 --- a/scripts/build-tools.js +++ b/scripts/build-tools.js @@ -9,7 +9,7 @@ const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPa let githubExtractData = await getData(); let automatedTools = await convertTools(githubExtractData); - fs.writeFileSync(automatedToolsPath, JSON.stringify(automatedTools, null, ' ')); + await fs.writeFile(automatedToolsPath, JSON.stringify(automatedTools, null, ' ')); await combineTools(automatedTools, require(manualToolsPath), toolsPath, tagsPath); } catch (err) { From 7279d793b7e19122545f6efe0ac538f271d7d2b3 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sat, 19 Oct 2024 20:01:42 +0530 Subject: [PATCH 39/44] commit to re run the workflow --- tests/tools/combine-tools.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 0be213a4444..90cc9e80f8e 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -256,4 +256,5 @@ describe('combineTools function', () => { } expect(error).toBeDefined(); }); + }); From 76014408122e16a781ae61a9a110dfb9565110df Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 21 Oct 2024 09:36:17 +0530 Subject: [PATCH 40/44] test upadted --- tests/build-newsroom-videos.test.js | 7 ++++--- tests/build-tools.test.js | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/build-newsroom-videos.test.js b/tests/build-newsroom-videos.test.js index a43c55ea9cd..494f91f2734 100644 --- a/tests/build-newsroom-videos.test.js +++ b/tests/build-newsroom-videos.test.js @@ -1,13 +1,14 @@ const { readFileSync, removeSync, mkdirpSync } = require('fs-extra'); -const { resolve } = require('path'); +const { resolve, join } = require('path'); const { buildNewsroomVideos } = require('../scripts/build-newsroom-videos'); const { mockApiResponse, expectedResult } = require('./fixtures/newsroomData'); const fetch = require('node-fetch-2'); +const os = require('os'); jest.mock('node-fetch-2', () => jest.fn()); describe('buildNewsroomVideos', () => { - const testDir = resolve(__dirname, 'test_config'); + const testDir = join(os.tmpdir(), 'test_config'); const testFilePath = resolve(testDir, 'newsroom_videos.json'); beforeAll(() => { @@ -89,7 +90,7 @@ describe('buildNewsroomVideos', () => { json: jest.fn().mockResolvedValue(mockApiResponse), }); - const invalidPath = '/invalid_dir/newsroom_videos.json'; + const invalidPath = resolve(os.tmpdir(), 'invalid_dir', 'newsroom_videos.json'); try { await buildNewsroomVideos(invalidPath); diff --git a/tests/build-tools.test.js b/tests/build-tools.test.js index 4377e1f298f..74524ddb977 100644 --- a/tests/build-tools.test.js +++ b/tests/build-tools.test.js @@ -3,6 +3,8 @@ const { resolve } = require('path'); const { buildTools } = require('../scripts/build-tools'); const { tagsData, manualTools, mockConvertedData, mockExtractData } = require('../tests/fixtures/buildToolsData'); const fs = require('fs-extra'); +const os = require('os'); +const path = require('path'); jest.mock('axios'); jest.mock('../scripts/tools/categorylist', () => ({ @@ -24,7 +26,7 @@ jest.mock('../scripts/tools/tags-color', () => ({ })); describe('buildTools', () => { - const testDir = resolve(__dirname, 'test_config'); + const testDir = path.join(os.tmpdir(), 'test_config'); const toolsPath = resolve(testDir, 'tools.json'); const tagsPath = resolve(testDir, 'all-tags.json'); const automatedToolsPath = resolve(testDir, 'tools-automated.json'); @@ -33,7 +35,6 @@ describe('buildTools', () => { beforeAll(() => { consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {}); - fs.ensureDirSync(testDir); fs.outputFileSync(manualToolsPath, JSON.stringify(manualTools)); }); @@ -81,7 +82,7 @@ describe('buildTools', () => { it('should handle file write errors', async () => { axios.get.mockResolvedValue({ data: mockExtractData }); - const invalidPath = '/invalid_dir/tools.json'; + const invalidPath = path.resolve(os.tmpdir(), 'invalid_dir', 'tools.json'); try { await buildTools(invalidPath, manualToolsPath, toolsPath, tagsPath); From 11fcfe66df5801cc0d895c561e1012345caef4ed Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 5 Nov 2024 14:27:10 +0530 Subject: [PATCH 41/44] test updated --- scripts/tools/combine-tools.js | 2 +- tests/tools/combine-tools.test.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/tools/combine-tools.js b/scripts/tools/combine-tools.js index 6cd1d51ef9c..ec2c39f5fb5 100644 --- a/scripts/tools/combine-tools.js +++ b/scripts/tools/combine-tools.js @@ -114,7 +114,7 @@ const combineTools = async (automatedTools, manualTools, toolsPath, tagsPath) => finalToolsList.push(await getFinalTool(tool)) } } - if (manualTools[key] && manualTools[key].toolsList.length) { + if (manualTools[key]?.toolsList?.length) { for (const tool of manualTools[key].toolsList) { let isAsyncAPIrepo; const isValid = await validate(tool) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 90cc9e80f8e..9f677c11cbb 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -64,8 +64,6 @@ describe('combineTools function', () => { beforeAll(() => { manualTools = readJSON(manualToolsPath); automatedTools = readJSON(automatedToolsPath); - - consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {}); }); afterAll(() => { @@ -75,6 +73,14 @@ describe('combineTools function', () => { consoleErrorMock.mockRestore(); }); + beforeEach(() => { + consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => { }); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + it('should combine tools and create correct JSON files', async () => { await combineTools(automatedTools, manualTools, toolsPath, tagsPath); @@ -209,7 +215,7 @@ describe('combineTools function', () => { it('should throw an error when fs.writeFileSync fails', async () => { let error; - let invalidPath = "this/is/not/valid" + const invalidPath = "this/is/not/valid" try { await combineTools(automatedTools, manualTools, invalidPath, invalidPath); @@ -256,5 +262,5 @@ describe('combineTools function', () => { } expect(error).toBeDefined(); }); - + }); From 7536a96209894ddf258b191849e7cd3fd17666af Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 5 Nov 2024 14:30:16 +0530 Subject: [PATCH 42/44] add empty line at the end --- scripts/tools/combine-tools.js | 2 +- tests/fixtures/combineToolsData.js | 2 +- tests/tools/combine-tools.test.js | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/tools/combine-tools.js b/scripts/tools/combine-tools.js index ec2c39f5fb5..bb290d5166c 100644 --- a/scripts/tools/combine-tools.js +++ b/scripts/tools/combine-tools.js @@ -143,4 +143,4 @@ const combineTools = async (automatedTools, manualTools, toolsPath, tagsPath) => } } -module.exports = { combineTools } \ No newline at end of file +module.exports = { combineTools } diff --git a/tests/fixtures/combineToolsData.js b/tests/fixtures/combineToolsData.js index 30ef6102979..04c776e7fee 100644 --- a/tests/fixtures/combineToolsData.js +++ b/tests/fixtures/combineToolsData.js @@ -209,4 +209,4 @@ module.exports = { automatedToolsT12, invalidAutomatedToolsT10, manualToolsWithInvalidURLT11 -} \ No newline at end of file +} diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 9f677c11cbb..25636307459 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -262,5 +262,4 @@ describe('combineTools function', () => { } expect(error).toBeDefined(); }); - }); From 5164452424e4156bde1721643067178b931386f4 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 5 Nov 2024 14:35:39 +0530 Subject: [PATCH 43/44] fege --- tests/build-newsroom-videos.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/build-newsroom-videos.test.js b/tests/build-newsroom-videos.test.js index 494f91f2734..f49a55e96a5 100644 --- a/tests/build-newsroom-videos.test.js +++ b/tests/build-newsroom-videos.test.js @@ -9,7 +9,7 @@ jest.mock('node-fetch-2', () => jest.fn()); describe('buildNewsroomVideos', () => { const testDir = join(os.tmpdir(), 'test_config'); - const testFilePath = resolve(testDir, 'newsroom_videos.json'); + const testFilePath = join(testDir, 'newsroom_videos.json'); beforeAll(() => { mkdirpSync(testDir); From ca72a7fb3d130ac8f091680508d1494f7a33a27d Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Tue, 5 Nov 2024 14:40:20 +0530 Subject: [PATCH 44/44] fqefe --- tests/build-newsroom-videos.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/build-newsroom-videos.test.js b/tests/build-newsroom-videos.test.js index f49a55e96a5..494f91f2734 100644 --- a/tests/build-newsroom-videos.test.js +++ b/tests/build-newsroom-videos.test.js @@ -9,7 +9,7 @@ jest.mock('node-fetch-2', () => jest.fn()); describe('buildNewsroomVideos', () => { const testDir = join(os.tmpdir(), 'test_config'); - const testFilePath = join(testDir, 'newsroom_videos.json'); + const testFilePath = resolve(testDir, 'newsroom_videos.json'); beforeAll(() => { mkdirpSync(testDir);