-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add tests for build tools script #3245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ef5e32e
setup
vishvamsinh28 fdddfe1
added tests for errors
vishvamsinh28 23ba7b0
added tests for errors
vishvamsinh28 94d388a
build-tools tests added
vishvamsinh28 2397e01
testCache update
vishvamsinh28 5e9da70
fixtures updated
vishvamsinh28 c858834
fixtures updated
vishvamsinh28 c816f66
fixtures updated
vishvamsinh28 0c4126f
fefe
vishvamsinh28 6aa3677
Merge branch 'master' into BuildToolsTest
vishvamsinh28 8a9ba65
paths update
vishvamsinh28 2214648
Merge branch 'master' into BuildToolsTest
vishvamsinh28 11a5d05
added expect statements
vishvamsinh28 9e29a5a
Merge branch 'master' into BuildToolsTest
vishvamsinh28 aa91e09
Merge branch 'BuildToolsTest' of https://github.com/vishvamsinh28/web…
vishvamsinh28 26a4be2
tests updated
vishvamsinh28 6592626
Merge branch 'master' into BuildToolsTest
vishvamsinh28 b3b34f8
Merge branch 'master' into BuildToolsTest
vishvamsinh28 b744e49
fef
vishvamsinh28 9d00110
fef
vishvamsinh28 7b8a407
fefwf
vishvamsinh28 0c4efb2
fwqwf
vishvamsinh28 61b3e16
fwaf
vishvamsinh28 e99f5cf
fwfw
vishvamsinh28 5cbe440
test updated
vishvamsinh28 bdf13cf
Merge branch 'master' into BuildToolsTest
vishvamsinh28 4600250
remove redundant tests
anshgoyalevil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,33 @@ | ||
| const { getData } = require('./tools/extract-tools-github'); | ||
| const { convertTools } = require('./tools/tools-object'); | ||
| const { combineTools } = require('./tools/combine-tools'); | ||
| const manualTools = require('../config/tools-manual.json') | ||
|
|
||
| const fs = require('fs'); | ||
| const { resolve } = require('path'); | ||
|
|
||
| const buildTools = async () => { | ||
| const buildTools = async (automatedToolsPath, manualToolsPath, toolsPath, tagsPath) => { | ||
| 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); | ||
|
|
||
| await combineTools(automatedTools, require(manualToolsPath), toolsPath, tagsPath); | ||
| } catch (err) { | ||
| console.log(err); | ||
| throw err | ||
| throw new Error(`An error occurred while building tools: ${err.message}`); | ||
| } | ||
| }; | ||
|
|
||
| buildTools(); | ||
| /* istanbul ignore next */ | ||
| if (require.main === module) { | ||
anshgoyalevil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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); | ||
| } | ||
|
|
||
| module.exports = { buildTools }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does final tools signify?? |
||
| fs.writeFileSync(tagsPath,JSON.stringify({ languages: languageList, technologies: technologyList }),) | ||
| } | ||
|
|
||
| module.exports = { combineTools } | ||
anshgoyalevil marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| 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'); | ||
|
|
||
| jest.mock('axios'); | ||
| jest.mock('../scripts/tools/categorylist', () => ({ | ||
| categoryList: [ | ||
| { name: 'Category1', description: 'Description for Category1' }, | ||
| { name: 'Category2', description: 'Description for Category2' } | ||
| ] | ||
| })); | ||
|
|
||
| jest.mock('../scripts/tools/tags-color', () => ({ | ||
| languagesColor: [ | ||
| { name: 'JavaScript', color: 'bg-[#f1e05a]', borderColor: 'border-[#f1e05a]' }, | ||
| { name: 'Python', color: 'bg-[#3572A5]', borderColor: 'border-[#3572A5]' } | ||
| ], | ||
| technologiesColor: [ | ||
| { name: 'React', color: 'bg-[#61dafb]', borderColor: 'border-[#61dafb]' }, | ||
| { name: 'Node.js', color: 'bg-[#68a063]', borderColor: 'border-[#68a063]' } | ||
| ] | ||
| })); | ||
|
|
||
| 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'); | ||
|
|
||
| beforeAll(() => { | ||
| fs.mkdirSync(testDir, { recursive: true }); | ||
| fs.writeFileSync(manualToolsPath, JSON.stringify(manualTools)); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| fs.rmSync(testDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should extract, convert, combine tools, and write to file', async () => { | ||
| axios.get.mockResolvedValue({ data: mockExtractData }); | ||
|
|
||
| await buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath); | ||
|
|
||
| const automatedToolsContent = JSON.parse(fs.readFileSync(automatedToolsPath, 'utf8')); | ||
| const combinedToolsContent = JSON.parse(fs.readFileSync(toolsPath, 'utf8')); | ||
| const tagsContent = JSON.parse(fs.readFileSync(tagsPath, 'utf8')); | ||
|
|
||
| expect(Object.keys(automatedToolsContent)).toEqual(Object.keys(mockConvertedData)); | ||
| expect(automatedToolsContent["Category1"].description).toEqual(mockConvertedData["Category1"].description); | ||
| expect(automatedToolsContent["Category2"].description).toEqual(mockConvertedData["Category2"].description); | ||
|
|
||
| expect(combinedToolsContent).toHaveProperty('Category1'); | ||
| expect(combinedToolsContent).toHaveProperty('Category2'); | ||
| expect(combinedToolsContent["Category1"].description).toEqual(mockConvertedData["Category1"].description); | ||
| expect(combinedToolsContent["Category2"].description).toEqual(mockConvertedData["Category2"].description); | ||
|
|
||
| expect(tagsContent).toEqual(tagsData); | ||
|
|
||
| }); | ||
|
|
||
| it('should handle getData error', async () => { | ||
| axios.get.mockRejectedValue(new Error('Extract error')); | ||
|
|
||
| try { | ||
| await buildTools(automatedToolsPath, manualToolsPath, toolsPath, tagsPath); | ||
| } catch (err) { | ||
| expect(err.message).toContain('Extract error'); | ||
| } | ||
| }); | ||
|
|
||
| it('should handle file write errors', async () => { | ||
| axios.get.mockResolvedValue({ data: mockExtractData }); | ||
|
|
||
| const invalidPath = '/invalid_dir/tools.json'; | ||
|
|
||
| try { | ||
| await buildTools(invalidPath, manualToolsPath, toolsPath, tagsPath); | ||
| } catch (err) { | ||
| expect(err.message).toMatch(/ENOENT|EACCES/); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| const tagsData = { | ||
| languages: [ | ||
| { name: 'JavaScript', color: 'bg-[#f1e05a]', borderColor: 'border-[#f1e05a]' }, | ||
| { name: 'Python', color: 'bg-[#3572A5]', borderColor: 'border-[#3572A5]' }, | ||
| ], | ||
| technologies: [ | ||
| { name: 'React', color: 'bg-[#61dafb]', borderColor: 'border-[#61dafb]' }, | ||
| { name: 'Node.js', color: 'bg-[#68a063]', borderColor: 'border-[#68a063]' }, | ||
| ], | ||
| }; | ||
|
|
||
| const manualTools = [ | ||
| { | ||
| title: "Manual Tool 1", | ||
| description: "Description for manual tool 1", | ||
| links: { repoUrl: "https://github.com/manual/tool1" }, | ||
| filters: { categories: ["Category1"], language: "JavaScript", technology: ["React"] } | ||
| }, | ||
| { | ||
| title: "Manual Tool 2", | ||
| description: "Description for manual tool 2", | ||
| links: { repoUrl: "https://github.com/manual/tool2" }, | ||
| filters: { categories: ["Category2"], language: "Python", technology: ["Node.js"] } | ||
| }, | ||
| ]; | ||
|
|
||
| const mockConvertedData = { | ||
| "Category1": { | ||
| description: "Description for Category1", | ||
| toolsList: [ | ||
| { | ||
| title: "Tool 1", | ||
| description: "Description for tool 1", | ||
| links: { repoUrl: "https://github.com/tool1" }, | ||
| filters: { categories: ["Category1"], language: "JavaScript", technology: ["React"] } | ||
| } | ||
| ] | ||
| }, | ||
| "Category2": { | ||
| description: "Description for Category2", | ||
| toolsList: [ | ||
| { | ||
| title: "Tool 2", | ||
| description: "Description for tool 2", | ||
| links: { repoUrl: "https://github.com/tool2" }, | ||
| filters: { categories: ["Category2"], language: "Python", technology: ["Node.js"] } | ||
| } | ||
| ] | ||
| } | ||
| }; | ||
|
|
||
| const mockExtractData = { | ||
| items: [ | ||
| { | ||
| name: '.asyncapi-tool', | ||
| url: 'https://api.github.com/repositories/123456/contents/.asyncapi-tool?ref=abcdef', | ||
| repository: { | ||
| full_name: 'user/repo1', | ||
| html_url: 'https://github.com/user/repo1', | ||
| description: 'Description for repo1', | ||
| owner: { login: 'asyncapi' } | ||
| }, | ||
| path: '.asyncapi-tool' | ||
| }, | ||
| { | ||
| name: '.asyncapi-tool', | ||
| url: 'https://api.github.com/repositories/789012/contents/.asyncapi-tool?ref=ghijkl', | ||
| repository: { | ||
| full_name: 'user/repo2', | ||
| html_url: 'https://github.com/user/repo2', | ||
| description: 'Description for repo2', | ||
| owner: { login: 'asyncapi' } | ||
| }, | ||
| path: '.asyncapi-tool' | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| module.exports = { | ||
| tagsData, | ||
| manualTools, | ||
| mockConvertedData, | ||
| mockExtractData, | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.