Skip to content

Commit

Permalink
added test for main function
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Nov 28, 2024
1 parent 0fbdc06 commit 02e221b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/markdown/check-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ async function main() {

main();

module.exports = { validateBlogs, validateDocs, checkMarkdownFiles }
module.exports = { validateBlogs, validateDocs, checkMarkdownFiles, main }
16 changes: 16 additions & 0 deletions tests/markdown/check-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs').promises;
const path = require('path');
const os = require('os');
const {
main,
validateBlogs,
validateDocs,
checkMarkdownFiles
Expand Down Expand Up @@ -116,4 +117,19 @@ describe('Frontmatter Validator', () => {
mockReadFile.mockRestore();
});

it('should handle main function errors', async () => {
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {});
jest.spyOn(fs, 'readdir').mockRejectedValue(new Error('Test error'));

await main();

expect(mockConsoleError).toHaveBeenCalledWith(
'Failed to validate markdown files:',
expect.any(Error)
);
expect(mockExit).toHaveBeenCalledWith(1);

mockExit.mockRestore();
});

});

0 comments on commit 02e221b

Please sign in to comment.