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: add codecov to the project #3168

Merged
merged 35 commits into from
Oct 15, 2024
Merged

Conversation

vishvamsinh28
Copy link
Contributor

@vishvamsinh28 vishvamsinh28 commented Aug 28, 2024

This PR integrates Codecov into our CI workflow to enhance the visibility of our test coverage across the codebase. By adding Codecov, we aim to:

  1. Codecov will provide detailed reports on which lines of code are being covered by our tests and highlight any gaps in coverage. This helps identify areas that require additional testing.

  2. With Codecov, every PR will now include a comment indicating the impact on test coverage. This ensures that as new features or bug fixes are added, we can maintain or improve the test coverage, ensuring code quality remains high.

How Codecov Will Be Used:

Codecov is integrated with the CI workflow. Once tests are run, the coverage reports will be uploaded to Codecov.

  • Install the Codecov app for this repository.
  • Add the Codecov token to the repository secrets.

Codecov setup in forked repe :- vishvamsinh28#7
Codecov report for tests in forked repo :- vishvamsinh28#8

Summary by CodeRabbit

  • New Features

    • Enhanced pull request testing workflow with steps for dependency installation, linting, and coverage reporting.
    • Added coverage reporting capabilities to the Jest testing framework.
  • Bug Fixes

    • Ensured tests run only if a package.json file is present, preventing errors in environments without it.

Copy link

netlify bot commented Aug 28, 2024

Deploy Preview for asyncapi-website ready!

Name Link
🔨 Latest commit d745bb1
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/670ea89bd7558300084a664b
😎 Deploy Preview https://deploy-preview-3168--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.

@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Aug 28, 2024

⚡️ Lighthouse report for the changes in this PR:

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

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

@akshatnema akshatnema added the gsoc This label should be used for issues or discussions related to ideas for Google Summer of Code label Aug 28, 2024
@anshgoyalevil
Copy link
Member

Is there a way we can see the codecov coverage report before merging this PR?

@vishvamsinh28
Copy link
Contributor Author

Is there a way we can view the Codecov coverage report before merging this PR?

I tried testing it by opening a PR in my forked repo, but it didn't work, so I guess not 😅.

However, based on this comment, I think we're good to go.

Copy link
Member

@akshatnema akshatnema left a comment

Choose a reason for hiding this comment

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

@vishvamsinh28 Add following things in the PR:

  • Add proper PR description on why codecov is being added and how it will be used.
  • Add test runs for this branch in your forked PR and add the test workflow links in PR description.

.github/workflows/if-nodejs-pr-testing.yml Outdated Show resolved Hide resolved
@vishvamsinh28
Copy link
Contributor Author

vishvamsinh28 commented Aug 31, 2024

Added links to my PRs in forked repo

@anshgoyalevil @akshatnema

@sambhavgupta0705
Copy link
Member

@vishvamsinh28 can you please provide the PR link where we can have a look on the working of this feature

@sambhavgupta0705
Copy link
Member

/update

@@ -1,7 +1,8 @@
module.exports = {
verbose: true,
collectCoverage: true,
collectCoverageFrom: ['scripts/**/*.js'],
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need that jest will only include files that are directly imported in our test files for coverage.

Copy link
Member

Choose a reason for hiding this comment

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

That's the case. Jest is now taking fixture files also into coverage, and that's wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will update it for excluding fixture files

Copy link

coderabbitai bot commented Oct 15, 2024

Walkthrough

The pull request introduces modifications to the workflow for testing Node.js projects. Key changes include the addition of steps for installing dependencies, running tests, linting, generating release assets, and uploading coverage reports. The jest.config.js file is updated to enhance coverage reporting capabilities by adding new properties for coverage reporters and specifying the coverage directory.

Changes

File Path Change Summary
.github/workflows/if-nodejs-pr-testing.yml - Added step to install dependencies (npm ci).
- Updated test step to run only if package.json exists.
- Introduced linter step for ubuntu-latest.
- Added step for generating release assets.
- Added step for uploading coverage to Codecov.
jest.config.js - Added coverageReporters: ['text', 'lcov', 'json-summary'].
- Added coverageDirectory: 'coverage'.

Poem

In the garden of code where the bunnies play,
New steps have hopped in to brighten the day.
Dependencies installed, tests run with glee,
Coverage reported, as happy as can be!
With linting and assets, our workflow's a treat,
Hooray for the changes, oh what a feat! 🐇✨


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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

@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

🧹 Outside diff range and nitpick comments (1)
.github/workflows/if-nodejs-pr-testing.yml (1)

Line range hint 69-71: Consider running linter on all platforms

The addition of a linting step is excellent for maintaining code quality. However, currently, it's set to run only on ubuntu-latest. Consider running the linter on all platforms to ensure consistent code style across different environments.

- if: steps.packagejson.outputs.exists == 'true'
  name: Run linter
  run: npm run lint --if-present

This change would ensure that linting is performed regardless of the operating system.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 739f9a5 and d745bb1.

📒 Files selected for processing (2)
  • .github/workflows/if-nodejs-pr-testing.yml (2 hunks)
  • jest.config.js (1 hunks)
🧰 Additional context used
🔇 Additional comments (7)
jest.config.js (2)

4-5: LGTM: Coverage reporting configuration looks good.

The addition of coverageReporters and coverageDirectory is appropriate for integrating Codecov:

  • The selected reporters ('text', 'lcov', 'json-summary') provide a good balance of human-readable and machine-readable outputs.
  • Setting the coverage directory to 'coverage' follows common conventions.

These changes will enable detailed coverage reporting, supporting the PR's objective of enhancing visibility of test coverage.


9-9: LGTM: Newline added as requested.

The addition of a newline at the end of the file is a good practice and addresses the previous comment by sambhavgupta0705. This change should resolve any related linting issues.

.github/workflows/if-nodejs-pr-testing.yml (5)

63-65: LGTM: Dependency installation step added

The addition of the "Install dependencies" step using npm ci is a good practice for CI environments. It ensures that all required dependencies are installed consistently based on the package-lock.json file, promoting reproducible builds.


Line range hint 66-68: LGTM: Test step improved

The modification to the "Test" step is an improvement. By checking for the existence of package.json and using the --if-present flag, the workflow becomes more robust and flexible, accommodating projects that may not have a test script defined.


Line range hint 72-75: LGTM: Release assets generation step added

The addition of the "Run release assets generation" step is a good safeguard to ensure that PRs don't inadvertently break the release process. The use of the --if-present flag makes this step flexible for projects that may or may not have this script defined.


77-84: LGTM: Codecov integration implemented correctly

The addition of the Codecov upload step is well-implemented and aligns with the PR objectives. Good practices observed:

  1. Using a specific commit hash for the codecov action.
  2. Correctly referencing the CODECOV_TOKEN from secrets.
  3. Specifying the coverage file path.

The flag parameter has been removed as suggested in the past comments, which is the correct approach for this use case.


Line range hint 63-84: Overall assessment: Significant improvements to the CI workflow

The changes made to this workflow file significantly enhance the CI process for Node.js projects:

  1. Dependency installation ensures consistent environments.
  2. Conditional test and lint steps improve flexibility.
  3. Release asset generation safeguards the release process.
  4. Codecov integration provides valuable coverage insights.

These additions align well with the PR objectives and follow good CI practices. The workflow is now more robust and informative, which will contribute to maintaining and improving code quality in the project.

Consider the suggestion to run the linter on all platforms for more comprehensive code style checks.

@@ -1,7 +1,9 @@
module.exports = {
verbose: true,
collectCoverage: true,
coverageReporters: ['text', 'lcov', 'json-summary'],
coverageDirectory: 'coverage',
collectCoverageFrom: ['scripts/**/*.js'],
Copy link

@coderabbitai coderabbitai bot Oct 15, 2024

Choose a reason for hiding this comment

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

💡 Codebase verification

Coverage reports are not being generated.

Despite collectCoverage being enabled in jest.config.js, the coverage directory does not exist. This indicates that coverage reports are not being generated as expected.

Please ensure that:

  • Tests are executed with coverage collection enabled.
  • The test scripts are correctly configured to generate coverage reports.
  • There are no errors during test execution that prevent coverage generation.
🔗 Analysis chain

Verify coverage collection configuration.

The current collectCoverageFrom configuration includes only 'scripts/**/*.js'. Based on the previous discussion in the comments, there was a concern about including 'fixture' files in the coverage reports.

Please verify if the current configuration sufficiently excludes 'fixture' files from coverage reports. If not, consider updating it to explicitly exclude these files.

To check if 'fixture' files are being included in coverage reports, you can run the following command after running your tests:

If 'fixture' files are found in the coverage report and you want to exclude them, you might want to update the collectCoverageFrom configuration to something like:

collectCoverageFrom: ['scripts/**/*.js', '!**/fixtures/**']

This will include all .js files in the 'scripts' directory and its subdirectories, but exclude any files in 'fixtures' directories.



</details>

<details>
<summary>🏁 Scripts executed</summary>

The following scripts were executed for the analysis:

Script:

```shell
#!/bin/bash
# Description: Check if 'fixture' files are included in coverage reports

# Look for 'fixture' files in the coverage report
grep -r "fixture" coverage/lcov-report

# If any 'fixture' files are found, they will be listed. 
# If no output is produced, it means no 'fixture' files are included in the coverage report.

Length of output: 92


Script:

#!/bin/bash
# Description: Check if coverage directory exists and list its contents

if [ -d "coverage" ]; then
  echo "Coverage directory exists. Listing contents:"
  ls -la coverage
else
  echo "Coverage directory does not exist."
fi

Length of output: 100


Script:

#!/bin/bash
# Description: Verify if coverage collection is enabled in jest.config.js

if grep -q "collectCoverage: true" jest.config.js; then
  echo "Coverage collection is enabled in jest.config.js."
else
  echo "Coverage collection is NOT enabled in jest.config.js."
fi

Length of output: 157


Script:

#!/bin/bash
# Description: Display the current collectCoverageFrom configuration in jest.config.js

grep "collectCoverageFrom" jest.config.js || echo "collectCoverageFrom is not defined in jest.config.js."

Length of output: 85


Script:

#!/bin/bash
# Description: Check if coverageDirectory is specified in jest.config.js

grep "coverageDirectory" jest.config.js || echo "coverageDirectory is not defined in jest.config.js. Default coverage directory is 'coverage'."

Length of output: 72


Script:

#!/bin/bash
# Description: Search for any coverage report directories other than the default 'coverage'

# Common coverage report directories
coverage_dirs=("coverage" "coverage-report" "lcov-report" "reports/coverage")

for dir in "${coverage_dirs[@]}"; do
  if [ -d "$dir" ]; then
    echo "Found coverage directory: $dir"
    ls -la "$dir"
  fi
done

# Additionally, search for any directories containing 'lcov' or 'coverage' in their names
fd --type d --glob '*coverage*' --glob '*lcov*' . 

Length of output: 430


Script:

#!/bin/bash
# Description: Verify if tests have been executed to generate coverage reports

# Check if jest has been run by looking for recent test-related scripts in package.json
grep '"test"' package.json || echo "No test scripts found in package.json."

# Alternatively, check Git history for recent test executions
git log -n 1 --pretty=format:"%H" -- "**/*.test.js" || echo "No recent test commits found."

# Check for recent modifications in jest.config.js
git log -n 1 --pretty=format:"%H" jest.config.js || echo "No recent changes to jest.config.js found."

Length of output: 248

Copy link
Member

Choose a reason for hiding this comment

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

coverage directory has been added in the .gitignore, hence it won't be part of repo. The coverage is generated everytime during github action run.

Copy link

Choose a reason for hiding this comment

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

@akshatnema, thank you for the clarification. I understand that the coverage directory is gitignored and coverage reports are generated during the GitHub Actions run. That makes sense.

(_/)
(o.O)


✏️ Learnings added
Learnt from: akshatnema
PR: asyncapi/website#3168
File: jest.config.js:6-6
Timestamp: 2024-10-15T17:44:59.028Z
Learning: In this repository, the `coverage` directory is added to `.gitignore`, and coverage reports are generated during GitHub Actions runs.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@akshatnema
Copy link
Member

/rtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gsoc This label should be used for issues or discussions related to ideas for Google Summer of Code ready-to-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants