Skip to content
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

feat: increase code coverage #3517

Merged
merged 6 commits into from
Dec 27, 2024
Merged

Conversation

vishvamsinh28
Copy link
Contributor

@vishvamsinh28 vishvamsinh28 commented Dec 26, 2024

This PR increases the code coverage for the scripts, bringing it to 100%.

Summary by CodeRabbit

  • New Features

    • Added a function to ensure the existence of a directory before file operations.
  • Bug Fixes

    • Updated coverage reporting to exclude additional files from coverage metrics.
  • Tests

    • Introduced new test cases for enhanced error handling in file writing operations and directory creation.

Copy link

netlify bot commented Dec 26, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 6289c28
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/676ed8b7b88d11000863af88
😎 Deploy Preview https://deploy-preview-3517--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

coderabbitai bot commented Dec 26, 2024

Walkthrough

This pull request introduces several enhancements to test coverage and error handling across multiple files. The Jest configuration is updated to expand the coveragePathIgnorePatterns, a new function for ensuring directory existence is added to the build script, and new test cases are introduced to validate error handling in file writing and data processing functions. These modifications aim to improve the testing framework's robustness by addressing edge cases and ensuring proper error management.

Changes

File Change Summary
jest.config.js Expanded coveragePathIgnorePatterns to exclude scripts/tools/categorylist.js and scripts/tools/tags-color.js in addition to scripts/compose.js.
scripts/build-pages.js Added ensureDirectoryExists function to check and create target directories; updated exports to include this new function.
tests/dashboard/build-dashboard.test.js Added new test case for writeToFile function to handle write failures gracefully.
tests/index.test.js Added new test case for start function to check error handling when no finance data is found.
tests/build-pages.test.js Added test case for ensureDirectoryExists function to verify directory creation.

Possibly related PRs

Suggested labels

ready-to-merge, gsoc

Suggested reviewers

  • akshatnema
  • derberg
  • magicmatatjahu
  • devilkiller-ag
  • sambhavgupta0705

Poem

🐰 In the realm of code, where tests reside,
Coverage expands, with errors pushed aside.
Ignoring paths, with Jest's keen eye,
Robust and strong, our tests now fly!
A rabbit's dance of quality delight 🧪


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c863f71 and 6289c28.

📒 Files selected for processing (1)
  • tests/build-pages.test.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/build-pages.test.js

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Dec 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (52adc2d) to head (6289c28).
Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #3517      +/-   ##
===========================================
+ Coverage   98.66%   100.00%   +1.33%     
===========================================
  Files          21        19       -2     
  Lines         672       668       -4     
===========================================
+ Hits          663       668       +5     
+ Misses          9         0       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Dec 26, 2024

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 41
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3517--asyncapi-website.netlify.app/

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/index.test.js (1)

7-7: Address import order and missing semicolon.

Static analysis suggests moving the fs import above other local imports and adding a trailing semicolon for consistency. Here's a quick fix:

-const fs = require('fs')
+const fs = require('fs');
🧰 Tools
🪛 eslint

[error] 7-7: fs import should occur before import of ../scripts/build-rss

(import/order)


[error] 7-7: Insert ;

(prettier/prettier)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a2ea91 and b5cbb95.

📒 Files selected for processing (4)
  • jest.config.js (1 hunks)
  • scripts/build-pages.js (1 hunks)
  • tests/dashboard/build-dashboard.test.js (1 hunks)
  • tests/index.test.js (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • scripts/build-pages.js
🧰 Additional context used
🪛 eslint
tests/index.test.js

[error] 7-7: fs import should occur before import of ../scripts/build-rss

(import/order)


[error] 7-7: Insert ;

(prettier/prettier)

tests/dashboard/build-dashboard.test.js

[error] 199-200: Delete ⏎····

(prettier/prettier)


[error] 201-202: Delete ··⏎

(prettier/prettier)

🔇 Additional comments (2)
jest.config.js (1)

7-7: Consider reconsidering these ignore patterns if the goal is to reach 100% coverage.

You're ignoring two additional script files (categorylist.js, tags-color.js) in coveragePathIgnorePatterns. If your PR aims to achieve maximum coverage, it may be counterproductive to exempt these files.

tests/index.test.js (1)

36-45: Good improvement - ensures error handling is tested.

The test effectively mocks readdirSync to return an empty array, verifying that the start function throws the expected error. This significantly fortifies negative path coverage.

Comment on lines 198 to 202
it('should handle write failures gracefully', async () => {

await expect(writeToFile).rejects.toThrow();
});

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Ensure the test invocation covers the function call.

Your test awaits writeToFile but doesn't explicitly invoke it with parameters. Clarify whether this is intentional. If your intention is to test calling writeToFile() without arguments, adjust the test as follows to ensure it actually attempts a call:

- await expect(writeToFile).rejects.toThrow();
+ await expect(writeToFile()).rejects.toThrow();

Also, remove extra blank lines for compliance with the style guide.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('should handle write failures gracefully', async () => {
await expect(writeToFile).rejects.toThrow();
});
it('should handle write failures gracefully', async () => {
await expect(writeToFile()).rejects.toThrow();
});
🧰 Tools
🪛 eslint

[error] 199-200: Delete ⏎····

(prettier/prettier)


[error] 201-202: Delete ··⏎

(prettier/prettier)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
tests/index.test.js (2)

7-7: Fix import order.

Move the fs import before the local imports to follow the standard import ordering convention:

  • Built-in modules
  • External dependencies
  • Local imports
+const fs = require('fs');
const rssFeed = require('../scripts/build-rss');
const { buildPostList } = require('../scripts/build-post-list');
const buildCaseStudiesList = require('../scripts/casestudies');
const buildAdoptersList = require('../scripts/adopters');
const buildFinanceInfoList = require('../scripts/finance');
const start = require('../scripts/index');
-const fs = require('fs');
🧰 Tools
🪛 eslint

[error] 7-7: fs import should occur before import of ../scripts/build-rss

(import/order)


37-45: LGTM! Consider adding more error scenarios.

The test case effectively validates the error handling when no finance data is found. To achieve 100% coverage, consider adding tests for:

  1. Error scenarios in other build functions (buildPostList, buildCaseStudiesList, etc.)
  2. Error handling in the RSS feed generation

Would you like me to help generate additional test cases for these scenarios?

tests/dashboard/build-dashboard.test.js (1)

198-202: LGTM! Clean up formatting.

The test case effectively validates write failures. Remove the extra blank lines to maintain consistent formatting:

 it('should handle write failures gracefully', async () => {
-    
   await expect(writeToFile()).rejects.toThrow();
-  });  
-
+  });
🧰 Tools
🪛 eslint

[error] 199-200: Delete ⏎····

(prettier/prettier)


[error] 201-202: Delete ··⏎

(prettier/prettier)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5cbb95 and facaa13.

📒 Files selected for processing (2)
  • tests/dashboard/build-dashboard.test.js (1 hunks)
  • tests/index.test.js (2 hunks)
🧰 Additional context used
🪛 eslint
tests/dashboard/build-dashboard.test.js

[error] 199-200: Delete ⏎····

(prettier/prettier)


[error] 201-202: Delete ··⏎

(prettier/prettier)

tests/index.test.js

[error] 7-7: fs import should occur before import of ../scripts/build-rss

(import/order)

Comment on lines 11 to 13
if (!fs.existsSync(TARGET_DIR)) {
fs.mkdirSync(TARGET_DIR, { recursive: true });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test that enters this if clause?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, added a test for it

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/build-pages.js (1)

64-64: Resolve formatting/linting issue.
Ensure consistency with the project's style guide by adding proper spacing and a trailing semicolon.

-module.exports = { copyAndRenameFiles,capitalizeJsxTags, ensureDirectoryExists }
+module.exports = { copyAndRenameFiles, capitalizeJsxTags, ensureDirectoryExists };
🧰 Tools
🪛 eslint

[error] 64-64: Replace capitalizeJsxTags,·ensureDirectoryExists·} with ·capitalizeJsxTags,·ensureDirectoryExists·};⏎

(prettier/prettier)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between facaa13 and c863f71.

📒 Files selected for processing (2)
  • scripts/build-pages.js (2 hunks)
  • tests/build-pages.test.js (2 hunks)
🧰 Additional context used
🪛 eslint
tests/build-pages.test.js

[error] 50-50: 'TEST_DIR' is already declared in the upper scope on line 20 column 9.

(no-shadow)

scripts/build-pages.js

[error] 64-64: Replace capitalizeJsxTags,·ensureDirectoryExists·} with ·capitalizeJsxTags,·ensureDirectoryExists·};⏎

(prettier/prettier)

🔇 Additional comments (3)
tests/build-pages.test.js (1)

3-3: Successfully imported the new utility function.
It's great to see ensureDirectoryExists added to the test. This improves maintainability by clearly separating responsibilities for directory creation from file operations.

scripts/build-pages.js (2)

10-13: Robust directory creation logic.
Using fs.mkdirSync(directory, { recursive: true }) ensures that nested directories will be created as needed. Consider wrapping file operations in a try/catch block if you need to handle errors more gracefully.


16-16: Automatic directory initialization is a good practice.
Calling ensureDirectoryExists(TARGET_DIR) before copying and renaming files is a clean way to avoid file operation errors.

tests/build-pages.test.js Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@anshgoyalevil
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit 160a462 into asyncapi:master Dec 27, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants