From 7bbc0a8c98644f777eb433e6f6bc55883195b994 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Sun, 28 Jul 2024 23:08:40 +0530 Subject: [PATCH 01/49] 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 363e34188161..f3997b06d1d7 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 f929f00095b1..602262428fa1 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 000000000000..1184da03e718 --- /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 000000000000..47469bc1a7e7 --- /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 000000000000..352f8e16f329 --- /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/49] 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 352f8e16f329..0e8cdff8fb66 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/49] 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 0e8cdff8fb66..5f7177969095 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/49] 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 f3997b06d1d7..e8c380a62981 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/49] 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 5f7177969095..754b7f6cfbbd 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/49] 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 754b7f6cfbbd..64a090eb17cd 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/49] 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 64a090eb17cd..9d4bc6d794dc 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/49] 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 9d4bc6d794dc..b1a61e653483 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/49] 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 b1a61e653483..c81dd5b47e86 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/49] 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 c81dd5b47e86..611128b4393a 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/49] 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 611128b4393a..153ffd6239e6 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/49] 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 153ffd6239e6..70ccfb58d35b 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/49] 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 70ccfb58d35b..153ffd6239e6 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/49] 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 153ffd6239e6..202259c564e3 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/49] 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 202259c564e3..5d106d903c96 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/49] 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 5d106d903c96..71ec1edd6169 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/49] 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 71ec1edd6169..78a7c048cf0d 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/49] 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 602262428fa1..a251c7da0497 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 78a7c048cf0d..89cf04607557 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/49] 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 000000000000..e96c025370be --- /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 89cf04607557..5bbe104b536b 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/49] 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 e96c025370be..9c3a3e1eb435 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 5bbe104b536b..52ad58b4aaa7 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/49] 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 9c3a3e1eb435..0dce8a0e4922 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 52ad58b4aaa7..bb4712dfc280 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/49] 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 0dce8a0e4922..c4a0021cc425 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 bb4712dfc280..f3abca4a5d9d 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/49] 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 f3abca4a5d9d..d2c1345a6703 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/49] 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 2fd0ef70d1c7..6cd1d51ef9c0 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 c4a0021cc425..30ef61029796 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 d2c1345a6703..78fee5441b2b 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/49] 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 04c6a05113d8..1f5870ed6c03 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/49] 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 1f5870ed6c03..84965815dcc4 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/49] 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 84965815dcc4..05c9e85bcb94 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 2bc4592e8e11..c8d0a029079e 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/49] 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 05c9e85bcb94..84965815dcc4 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 c8d0a029079e..2bc4592e8e11 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/49] 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 2bc4592e8e11..d1de02f54352 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 78fee5441b2b..0be213a4444d 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/49] 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 b67ee0378cf2..f8a06787bdf5 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 84965815dcc4..e0ade7dd39ed 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 63f571466944..704b479fa0e3 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 d1de02f54352..7be2e5148e85 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/49] 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 e0ade7dd39ed..d3e4d6c10897 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/49] 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 0be213a4444d..90cc9e80f8e7 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/49] 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 f8a06787bdf5..f4cf83066925 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 d3e4d6c10897..2b7c47768f78 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/49] 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 bea2b1cc43e4..3e06c5cffdb9 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 04ba37b586eb..aab6109d1349 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 f4cf83066925..383927765d36 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 2b7c47768f78..c5cce74a7cb1 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 704b479fa0e3..a43c55ea9cd0 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 7be2e5148e85..4377e1f298ff 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/49] 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 383927765d36..0cd466926aaa 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/49] 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 c5cce74a7cb1..8d1d031862f3 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/49] 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 90cc9e80f8e7..0be213a4444d 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/49] 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 0cd466926aaa..383927765d36 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 8d1d031862f3..c5cce74a7cb1 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/49] 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 0be213a4444d..90cc9e80f8e7 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/49] 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 a43c55ea9cd0..494f91f27341 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 4377e1f298ff..74524ddb9775 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/49] 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 6cd1d51ef9c0..ec2c39f5fb50 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 90cc9e80f8e7..9f677c11cbb8 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/49] 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 ec2c39f5fb50..bb290d5166c6 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 30ef61029796..04c776e7feee 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 9f677c11cbb8..256363074595 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/49] 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 494f91f27341..f49a55e96a55 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/49] 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 f49a55e96a55..494f91f27341 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); From 1698ce2eb26131f1b4d6b32f54e837afd717cca8 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Wed, 13 Nov 2024 17:32:38 +0530 Subject: [PATCH 45/49] fege --- 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 256363074595..c9d3ba334fdd 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -262,4 +262,5 @@ describe('combineTools function', () => { } expect(error).toBeDefined(); }); + }); From 993310ed65a72cf546b7a7b1c38a258212df9464 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Fri, 29 Nov 2024 12:15:49 +0530 Subject: [PATCH 46/49] removed try/catch block from tests related to errors --- tests/tools/combine-tools.test.js | 48 +++++++------------------------ 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index c9d3ba334fdd..c9f6fd968470 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -214,53 +214,25 @@ describe('combineTools function', () => { }); it('should throw an error when fs.writeFileSync fails', async () => { - let error; - const 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(); + const invalidPath = 'this/is/not/valid'; + await expect(combineTools(automatedTools, manualTools, invalidPath, invalidPath)) + .rejects.toThrow(/ENOENT|EACCES/); }); 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(); + await expect(combineTools(invalidAutomatedToolsT10, manualTools, toolsPath, tagsPath)) + .rejects.toThrow('Error combining tools'); }); 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(); + await expect(combineTools(automatedTools, manualToolsWithInvalidURLT11, toolsPath, tagsPath)) + .rejects.toThrow('Invalid URL'); }); 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'); - } - expect(error).toBeDefined(); + await expect(combineTools(automatedToolsT12, {}, toolsPath, tagsPath)) + .rejects.toThrow('Converting circular structure to JSON'); }); - + }); From 5d23088a8207b0c2e3a4be1d1be22246cd7d1aa2 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 9 Dec 2024 12:18:16 +0530 Subject: [PATCH 47/49] remove new line --- tests/tools/combine-tools.test.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index c9f6fd968470..621b5a68f966 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -94,7 +94,6 @@ describe('combineTools function', () => { }); it('should handle tools with missing language or technology', async () => { - await combineTools({}, manualToolsWithMissingData, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); @@ -102,7 +101,6 @@ describe('combineTools function', () => { }); it('should sort tools alphabetically by title', async () => { - await combineTools(manualToolsToSort, {}, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); @@ -111,7 +109,6 @@ describe('combineTools function', () => { }); it('should log validation errors to console.error', async () => { - await combineTools(automatedToolsT4, manualToolsT4, toolsPath, tagsPath); const errorCalls = console.error.mock.calls; @@ -126,7 +123,6 @@ describe('combineTools function', () => { }); it('should handle tools with multiple languages, including new ones', async () => { - await combineTools(automatedToolsT5, {}, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); @@ -142,7 +138,6 @@ describe('combineTools function', () => { }); it('should add a new language and technology when not found in the existing lists', async () => { - await combineTools(automatedToolsT6, {}, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); @@ -168,7 +163,6 @@ describe('combineTools function', () => { }); it('should add a new language when it is not found in the existing languages list', async () => { - await combineTools(automatedToolsT7, {}, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); @@ -186,10 +180,8 @@ describe('combineTools function', () => { }); it('should handle valid tool objects', async () => { - await combineTools(automatedToolsT8, manualToolsT8, toolsPath, tagsPath); - const tagsData = readJSON(tagsPath); expect(tagsData.languages).toContainEqual({ name: 'JavaScript', @@ -204,7 +196,6 @@ describe('combineTools function', () => { }); it('should handle tool objects without repoUrl', async () => { - await combineTools(automatedToolsT9, manualToolsT9, toolsPath, tagsPath); const combinedTools = readJSON(toolsPath); From fca4dccb1b60b5c39e719127a8da2503aaef609e Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 9 Dec 2024 12:19:42 +0530 Subject: [PATCH 48/49] fix indentation errors --- tests/fixtures/combineToolsData.js | 294 ++++++++++++++--------------- 1 file changed, 147 insertions(+), 147 deletions(-) diff --git a/tests/fixtures/combineToolsData.js b/tests/fixtures/combineToolsData.js index 04c776e7feee..452764ac9192 100644 --- a/tests/fixtures/combineToolsData.js +++ b/tests/fixtures/combineToolsData.js @@ -1,212 +1,212 @@ 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]' - } - ] + 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' } - } + { + 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' } - } - ] - } + 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' } + 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] - } + category1: { + description: 'Category 1 Description', + toolsList: [toolWithMultipleLanguages], + }, }; const invalidToolT4 = { title: 'Invalid Tool' }; const automatedToolsT4 = { - 'category1': { - description: 'Category 1 Description', - toolsList: [] - } + category1: { + description: 'Category 1 Description', + toolsList: [], + }, }; const manualToolsT4 = { - 'category1': { - toolsList: [invalidToolT4] - } + category1: { + toolsList: [invalidToolT4], + }, }; const toolWithNewTagsT6 = { - title: 'New Tags Tool', - filters: { - language: 'NewLanguage', - technology: ['NewTechnology'] - }, - links: { repoUrl: 'https://github.com/example/new-tags-tool' } + 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] - } + category1: { + description: 'Category 1 Description', + toolsList: [toolWithNewTagsT6], + }, }; const toolWithNewLanguageT7 = { - title: 'New Language Tool', - filters: { - language: 'Go', - technology: ['Node.js'] - }, - links: { repoUrl: 'https://github.com/example/new-language-tool' } + 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] - } + 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' } + 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: [] - } + category1: { + description: 'Category 1 Description', + toolsList: [], + }, }; const manualToolsT8 = { - category1: { - toolsList: [validToolT8] - } + category1: { + toolsList: [validToolT8], + }, }; const toolWithoutRepoUrlT9 = { - title: 'Tool Without Repo', - filters: { - language: 'Python', - technology: ['Flask'] - }, - links: {} + title: 'Tool Without Repo', + filters: { + language: 'Python', + technology: ['Flask'], + }, + links: {}, }; const automatedToolsT9 = { - category1: { - description: 'Category 1 Description', - toolsList: [] - } + category1: { + description: 'Category 1 Description', + toolsList: [], + }, }; const manualToolsT9 = { - category1: { - toolsList: [toolWithoutRepoUrlT9] - } + category1: { + toolsList: [toolWithoutRepoUrlT9], + }, }; const invalidAutomatedToolsT10 = { - invalidCategory: { - description: 'Invalid Category Description', - toolsList: [] - } + invalidCategory: { + description: 'Invalid Category Description', + toolsList: [], + }, }; const manualToolsWithInvalidURLT11 = { - category1: { - toolsList: [ - { - title: 'Tool with Invalid URL', - filters: { language: 'JavaScript' }, - links: { repoUrl: 'invalid-url' } - } - ] - } + category1: { + toolsList: [ + { + title: 'Tool with Invalid URL', + filters: { language: 'JavaScript' }, + links: { repoUrl: 'invalid-url' }, + }, + ], + }, }; const circularTool = { - title: 'Circular Tool', - filters: { - language: 'JavaScript', - technology: ['Node.js'] - }, - links: { repoUrl: 'https://github.com/asyncapi/circular-tool' } + title: 'Circular Tool', + filters: { + language: 'JavaScript', + technology: ['Node.js'], + }, + links: { repoUrl: 'https://github.com/asyncapi/circular-tool' }, }; const automatedToolsT12 = { - category1: { - description: 'Category 1', - toolsList: [circularTool] - } + category1: { + description: 'Category 1', + toolsList: [circularTool], + }, }; module.exports = { - expectedDataT1, - manualToolsWithMissingData, - manualToolsToSort, - automatedToolsT5, - automatedToolsT4, - manualToolsT4, - automatedToolsT6, - automatedToolsT7, - automatedToolsT8, - manualToolsT8, - automatedToolsT9, - manualToolsT9, - circularTool, - automatedToolsT12, - invalidAutomatedToolsT10, - manualToolsWithInvalidURLT11 -} + expectedDataT1, + manualToolsWithMissingData, + manualToolsToSort, + automatedToolsT5, + automatedToolsT4, + manualToolsT4, + automatedToolsT6, + automatedToolsT7, + automatedToolsT8, + manualToolsT8, + automatedToolsT9, + manualToolsT9, + circularTool, + automatedToolsT12, + invalidAutomatedToolsT10, + manualToolsWithInvalidURLT11, +}; From 98f3238284329e0ad5290751fca7bd87be6e28b5 Mon Sep 17 00:00:00 2001 From: Vishvamsinh Vaghela Date: Mon, 9 Dec 2024 12:56:11 +0530 Subject: [PATCH 49/49] updated error logging --- scripts/tools/combine-tools.js | 11 +++++++---- tests/tools/combine-tools.test.js | 10 +++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/tools/combine-tools.js b/scripts/tools/combine-tools.js index bb290d5166c6..1b1367b15ccb 100644 --- a/scripts/tools/combine-tools.js +++ b/scripts/tools/combine-tools.js @@ -126,10 +126,13 @@ const combineTools = async (automatedTools, manualTools, toolsPath, tagsPath) => 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)); + console.error({ + message: 'Tool validation failed', + tool: tool.title, + source: 'manual-tools.json', + errors: validate.errors, + note: 'Script continues execution, error logged for investigation' + }); } } } diff --git a/tests/tools/combine-tools.test.js b/tests/tools/combine-tools.test.js index 621b5a68f966..622067a57462 100644 --- a/tests/tools/combine-tools.test.js +++ b/tests/tools/combine-tools.test.js @@ -111,12 +111,12 @@ describe('combineTools function', () => { it('should log validation errors to console.error', async () => { await combineTools(automatedToolsT4, manualToolsT4, toolsPath, tagsPath); - const errorCalls = console.error.mock.calls; + const { message, tool, source, note } = console.error.mock.calls[0][0]; - 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(message).toBe('Tool validation failed'); + expect(tool).toBe('Invalid Tool'); + expect(source).toBe('manual-tools.json'); + expect(note).toBe('Script continues execution, error logged for investigation'); expect(fs.existsSync(toolsPath)).toBe(true); expect(fs.existsSync(tagsPath)).toBe(true);