-
-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: the bug in the Netlify function response structure #4694
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
Open
Devnil434
wants to merge
12
commits into
asyncapi:master
Choose a base branch
from
Devnil434:fix-Netlify-function-response-structure
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+221
−163
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
79ad26e
fixed the bug in the Netlify function response structure
32cabe5
Merge branch 'master' into fix-Netlify-function-response-structure
Devnil434 ea314e9
fix error in test files
af631cc
Merge branch 'fix-Netlify-function-response-structure' of https://git…
fef88f1
fix errors
1fb1fcd
fix
58aaa32
fix finance file errors
a75d74e
fix
4012666
fix errors
3c39501
fix test errors
9af846b
fix sript file errors
9f0563a
Merge branch 'master' into fix-Netlify-function-response-structure
Devnil434 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
Some comments aren't visible on the classic Files Changed page.
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
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,79 +1,81 @@ | ||
| import fs from 'fs'; | ||
| import { dirname, resolve } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| import { buildUsecasesList } from './usecases/index'; | ||
| import { buildPostList } from './build-post-list'; | ||
| import { rssFeed } from './build-rss'; | ||
| import { buildCaseStudiesList } from './casestudies/index'; | ||
| import { buildFinanceInfoList } from './finance/index'; | ||
| import { buildToolsManual } from './build-tools'; | ||
|
|
||
| const currentFilePath = fileURLToPath(import.meta.url); | ||
| const currentDirPath = dirname(currentFilePath); | ||
| const automatedToolsPath = resolve(currentDirPath, '../config', 'tools-automated.json'); | ||
| const manualToolsPath = resolve(currentDirPath, '../config', 'tools-manual.json'); | ||
| const toolsPath = resolve(currentDirPath, '../config', 'tools.json'); | ||
| const tagsPath = resolve(currentDirPath, '../config', 'all-tags.json'); | ||
|
|
||
|
|
||
| /** | ||
| * Initiates the build process for the project's content. | ||
| * | ||
| * This asynchronous function orchestrates the creation of various content lists by processing designated directories and files. | ||
| * It builds the posts list, generates the blog RSS feed, creates the case studies list, compiles the adopters list, | ||
| * and combines tools data. | ||
| * For finance information, it reads the finance directory, filters and sorts numeric filenames representing years, and utilizes the latest year. | ||
| * The function throws an error if no valid finance data is found. | ||
| * | ||
| * @throws {Error} If no numeric finance data is found in the finance directory. | ||
| */ | ||
| async function start() { | ||
| const postDirectories = [ | ||
| ['pages/blog', '/blog'], | ||
| ['pages/docs', '/docs'], | ||
| ['pages/about', '/about'] | ||
| ]; | ||
| const basePath = 'pages'; | ||
| const writeFilePath = resolve(currentDirPath, '../config', 'posts.json'); | ||
|
|
||
| await buildPostList(postDirectories, basePath, writeFilePath); | ||
| await rssFeed('blog', 'AsyncAPI Initiative Blog RSS Feed', 'AsyncAPI Initiative Blog', 'rss.xml'); | ||
| await buildCaseStudiesList('config/casestudies', resolve(currentDirPath, '../config', 'case-studies.json')); | ||
|
|
||
| // Build tools manually to reflect changes in tools-manual.json | ||
| await buildToolsManual(automatedToolsPath, manualToolsPath, toolsPath, tagsPath); | ||
|
|
||
| await buildUsecasesList(); | ||
| const financeDir = resolve('.', 'config', 'finance'); | ||
|
|
||
| // loop through all the files finance in directory and find the latest year to build the finance info list | ||
| const yearsList = fs | ||
| .readdirSync(financeDir) | ||
| // filter out any files that are not numbers | ||
| .filter((file) => { | ||
| return !Number.isNaN(parseFloat(file)); | ||
| }) | ||
| // sort the years in descending order | ||
| .sort((a, b) => { | ||
| return parseFloat(b) - parseFloat(a); | ||
| }); | ||
|
|
||
| if (yearsList.length === 0) { | ||
| throw new Error('No finance data found in the finance directory.'); | ||
| } | ||
|
|
||
| const latestYear = yearsList[0]; | ||
|
|
||
| await buildFinanceInfoList({ | ||
| currentDir: '.', | ||
| configDir: 'config', | ||
| financeDir: 'finance', | ||
| year: latestYear, | ||
| jsonDataDir: 'json-data' | ||
| }); | ||
| } | ||
|
|
||
| export { start }; | ||
|
|
||
| start(); | ||
| import fs from 'fs'; | ||
| import { dirname, resolve } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| import { buildUsecasesList } from './usecases/index'; | ||
| import { buildPostList } from './build-post-list'; | ||
| import { rssFeed } from './build-rss'; | ||
| import { buildCaseStudiesList } from './casestudies/index'; | ||
| import { buildFinanceInfoList } from './finance/index'; | ||
| import { buildToolsManual } from './build-tools'; | ||
|
|
||
| const currentFilePath = fileURLToPath(import.meta.url); | ||
| const currentDirPath = dirname(currentFilePath); | ||
| const automatedToolsPath = resolve(currentDirPath, '../config', 'tools-automated.json'); | ||
| const manualToolsPath = resolve(currentDirPath, '../config', 'tools-manual.json'); | ||
| const toolsPath = resolve(currentDirPath, '../config', 'tools.json'); | ||
| const tagsPath = resolve(currentDirPath, '../config', 'all-tags.json'); | ||
|
|
||
|
|
||
| /** | ||
| * Initiates the build process for the project's content. | ||
| * | ||
| * This asynchronous function orchestrates the creation of various content lists by processing designated directories and files. | ||
| * It builds the posts list, generates the blog RSS feed, creates the case studies list, compiles the adopters list, | ||
| * and combines tools data. | ||
| * For finance information, it reads the finance directory, filters and sorts numeric directory names representing years, and utilizes the latest year. | ||
| * The function throws an error if no valid finance data is found. | ||
| * | ||
| * @throws {Error} If no numeric finance data is found in the finance directory. | ||
| */ | ||
| export async function start() { | ||
| const postDirectories = [ | ||
| ['pages/blog', '/blog'], | ||
| ['pages/docs', '/docs'], | ||
| ['pages/about', '/about'] | ||
| ]; | ||
| const basePath = 'pages'; | ||
| const writeFilePath = resolve(currentDirPath, '../config', 'posts.json'); | ||
|
|
||
| await buildPostList(postDirectories, basePath, writeFilePath); | ||
| await rssFeed('blog', 'AsyncAPI Initiative Blog RSS Feed', 'AsyncAPI Initiative Blog', 'rss.xml'); | ||
| await buildCaseStudiesList('config/casestudies', resolve(currentDirPath, '../config', 'case-studies.json')); | ||
|
|
||
| // Build tools manually to reflect changes in tools-manual.json | ||
| await buildToolsManual(automatedToolsPath, manualToolsPath, toolsPath, tagsPath); | ||
|
|
||
| await buildUsecasesList(); | ||
| const financeDir = resolve('.', 'config', 'finance'); | ||
|
|
||
| // loop through all the directories in finance directory and find the latest year to build the finance info list | ||
| const yearsList = fs | ||
| .readdirSync(financeDir) | ||
| // filter out any items that are not directories with numeric names | ||
| .filter((item) => { | ||
| const itemPath = resolve(financeDir, item); | ||
| return fs.statSync(itemPath).isDirectory() && !Number.isNaN(parseFloat(item)); | ||
| }) | ||
| // sort the years in descending order | ||
| .sort((a, b) => { | ||
| return parseFloat(b) - parseFloat(a); | ||
| }); | ||
|
|
||
| if (yearsList.length === 0) { | ||
| throw new Error('No finance data found in the finance directory.'); | ||
| } | ||
|
|
||
| const latestYear = yearsList[0]; | ||
|
|
||
| await buildFinanceInfoList({ | ||
| currentDir: '.', | ||
| configDir: 'config', | ||
| financeDir: 'finance', | ||
| year: latestYear, | ||
| jsonDataDir: 'json-data' | ||
| }); | ||
| } | ||
|
|
||
| // Only run the function if this file is executed directly | ||
| if (process.argv[1] === currentFilePath) { | ||
| start().catch(console.error); | ||
| } | ||
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,47 +1,54 @@ | ||
| import fs from 'fs'; | ||
|
|
||
| import { buildUsecasesList } from '../scripts/usecases/index'; | ||
| import { buildPostList } from '../scripts/build-post-list'; | ||
| import { rssFeed } from '../scripts/build-rss'; | ||
| import { buildCaseStudiesList } from '../scripts/casestudies/index'; | ||
| import { buildFinanceInfoList } from '../scripts/finance/index'; | ||
| import { start } from '../scripts/index'; | ||
|
|
||
| jest.mock('../scripts/build-rss'); | ||
| jest.mock('../scripts/build-post-list'); | ||
| jest.mock('../scripts/casestudies'); | ||
| jest.mock('../scripts/usecases'); | ||
| jest.mock('../scripts/finance'); | ||
|
|
||
| describe('start function', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| test('should call all functions in the correct order', async () => { | ||
| await start(); | ||
|
|
||
| expect(buildPostList).toHaveBeenCalled(); | ||
|
|
||
| expect(rssFeed).toHaveBeenCalledWith( | ||
| 'blog', | ||
| 'AsyncAPI Initiative Blog RSS Feed', | ||
| 'AsyncAPI Initiative Blog', | ||
| 'rss.xml' | ||
| ); | ||
|
|
||
| expect(buildCaseStudiesList).toHaveBeenCalled(); | ||
| expect(buildUsecasesList).toHaveBeenCalled(); | ||
| expect(buildFinanceInfoList).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('should throw an error if no finance data is found', async () => { | ||
| const readdirSyncSpy = jest.spyOn(fs, 'readdirSync').mockReturnValue([]); | ||
|
|
||
| await expect(start()).rejects.toThrow('No finance data found in the finance directory.'); | ||
| expect(readdirSyncSpy).toHaveBeenCalledTimes(1); | ||
| expect(buildFinanceInfoList).not.toHaveBeenCalled(); | ||
|
|
||
| readdirSyncSpy.mockRestore(); | ||
| }); | ||
| }); | ||
| import fs from 'fs'; | ||
|
|
||
| import { buildUsecasesList } from '../scripts/usecases/index'; | ||
| import { buildPostList } from '../scripts/build-post-list'; | ||
| import { rssFeed } from '../scripts/build-rss'; | ||
| import { buildCaseStudiesList } from '../scripts/casestudies/index'; | ||
| import { buildFinanceInfoList } from '../scripts/finance/index'; | ||
| import { start } from '../scripts/index'; | ||
|
|
||
| jest.mock('../scripts/build-rss'); | ||
| jest.mock('../scripts/build-post-list'); | ||
| jest.mock('../scripts/casestudies'); | ||
| jest.mock('../scripts/usecases'); | ||
| jest.mock('../scripts/finance'); | ||
|
|
||
| describe('start function', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| test('should call all functions in the correct order', async () => { | ||
| await start(); | ||
|
|
||
| expect(buildPostList).toHaveBeenCalled(); | ||
|
|
||
| expect(rssFeed).toHaveBeenCalledWith( | ||
| 'blog', | ||
| 'AsyncAPI Initiative Blog RSS Feed', | ||
| 'AsyncAPI Initiative Blog', | ||
| 'rss.xml' | ||
| ); | ||
|
|
||
| expect(buildCaseStudiesList).toHaveBeenCalled(); | ||
| expect(buildUsecasesList).toHaveBeenCalled(); | ||
| expect(buildFinanceInfoList).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('should throw an error if no finance data is found', async () => { | ||
| const readdirSyncSpy = jest.spyOn(fs, 'readdirSync').mockReturnValue([]); | ||
|
|
||
| // Since the start() function is called when the module is imported, | ||
| // we need to catch the error during the import process | ||
| await expect(start()).rejects.toThrow('No finance data found in the finance directory.'); | ||
|
|
||
| expect(readdirSyncSpy).toHaveBeenCalled(); | ||
| expect(buildFinanceInfoList).not.toHaveBeenCalled(); | ||
|
|
||
| readdirSyncSpy.mockRestore(); | ||
| }); | ||
|
|
||
| // Note: Testing the direct execution branch (lines 79-81 in scripts/index.ts) | ||
| // is challenging in Jest as it requires mocking module loading behavior. | ||
| // This coverage gap is acceptable as the branch is straightforward. | ||
| }); |
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,46 @@ | ||
| /** | ||
| * @jest-environment node | ||
| */ | ||
|
|
||
| // This test file specifically tests the direct execution path of scripts/index.ts | ||
| // by manipulating the module environment to simulate direct execution. | ||
|
|
||
| import fs from 'fs'; | ||
|
|
||
| // Mock all the imported functions to avoid actual file operations | ||
| jest.mock('../../scripts/build-post-list'); | ||
| jest.mock('../../scripts/build-rss'); | ||
| jest.mock('../../scripts/casestudies/index'); | ||
| jest.mock('../../scripts/build-tools'); | ||
| jest.mock('../../scripts/usecases/index'); | ||
| jest.mock('../../scripts/finance/index'); | ||
|
|
||
| describe('scripts/index.ts direct execution', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| test('should execute start function when run directly', async () => { | ||
| // Mock fs.readdirSync to return a valid year directory to avoid the error path | ||
| const readdirSyncSpy = jest.spyOn(fs, 'readdirSync').mockReturnValue(['2023'] as any); | ||
| const statSyncSpy = jest.spyOn(fs, 'statSync').mockReturnValue({ isDirectory: () => true } as any); | ||
|
|
||
| // We need to mock console.error to avoid polluting the test output | ||
| const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(); | ||
|
|
||
| // Set up process.argv to simulate direct execution | ||
| const originalArgv = process.argv; | ||
| const testFilePath = require.resolve('../../scripts/index'); | ||
| process.argv = ['', testFilePath]; | ||
|
|
||
| // Dynamically import the module to trigger the direct execution | ||
| // Using require to ensure the module is evaluated | ||
| await import('../../scripts/index'); | ||
|
|
||
| // Clean up | ||
| process.argv = originalArgv; | ||
| consoleErrorSpy.mockRestore(); | ||
| readdirSyncSpy.mockRestore(); | ||
| statSyncSpy.mockRestore(); | ||
| }); | ||
Devnil434 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 |
|---|---|---|
| @@ -1,36 +1,37 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "lib": [ | ||
| "dom", | ||
| "dom.iterable", | ||
| "esnext" | ||
| ], | ||
| "allowJs": true, | ||
| "skipLibCheck": true, | ||
| "strict": true, | ||
| "noEmit": true, | ||
| "esModuleInterop": true, | ||
| "module": "esnext", | ||
| "target": "ES2022", | ||
| "moduleResolution": "bundler", | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true, | ||
| "jsx": "preserve", | ||
| "incremental": true, | ||
| "paths": { | ||
| "@/*": [ | ||
| "./*" | ||
| ] | ||
| } | ||
| }, | ||
| "include": [ | ||
| "next-env.d.ts", | ||
| "**/*.ts", | ||
| "**/*.tsx", | ||
| "**/*.json" | ||
| ], | ||
| "exclude": [ | ||
| "node_modules", | ||
| "netlify" | ||
| ] | ||
| } | ||
| { | ||
| "compilerOptions": { | ||
| "lib": [ | ||
| "dom", | ||
| "dom.iterable", | ||
| "esnext" | ||
| ], | ||
| "allowJs": true, | ||
| "skipLibCheck": true, | ||
| "strict": true, | ||
| "noEmit": true, | ||
| "esModuleInterop": true, | ||
| "module": "esnext", | ||
| "target": "ES2022", | ||
| "moduleResolution": "bundler", | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true, | ||
| "jsx": "preserve", | ||
| "incremental": true, | ||
| "allowImportingTsExtensions": true, | ||
| "paths": { | ||
| "@/*": [ | ||
| "./*" | ||
| ] | ||
| } | ||
| }, | ||
| "include": [ | ||
| "next-env.d.ts", | ||
| "**/*.ts", | ||
| "**/*.tsx", | ||
| "**/*.json" | ||
| ], | ||
| "exclude": [ | ||
| "node_modules", | ||
| "netlify" | ||
| ] | ||
| } |
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.