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

Refactored src/components/GroupChatDetails from jest to vitest #3453

Merged

Conversation

syedali237
Copy link
Contributor

@syedali237 syedali237 commented Jan 27, 2025

What kind of change does this PR introduce?

Refactoring

Issue Number:

Fixes #3445

Snapshots/Videos:

N/A

If relevant, did you update the documentation?

No

Summary

Migrated test case from jest to vitest

Does this PR introduce a breaking change?

No

Checklist

CodeRabbit AI Review

  • I have reviewed and addressed all critical issues flagged by CodeRabbit AI
  • I have implemented or provided justification for each non-critical suggestion
  • I have documented my reasoning in the PR comments where CodeRabbit AI suggestions were not implemented

Test Coverage

  • I have written tests for all new changes/features
  • I have verified that test coverage meets or exceeds 95%
  • I have run the test suite locally and all tests pass

Other information

N/A

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • Tests
    • Updated test suite for Group Chat Details component to use Vitest mocking functions.
    • Removed commented-out imports and unnecessary waiting time in test cases.
    • Adjusted filename validation logic to allow files with ".test." in their names.
    • Removed Jest-related configurations and steps from the testing workflow, focusing solely on Vitest.

Copy link
Contributor

coderabbitai bot commented Jan 27, 2025

Warning

Rate limit exceeded

@varshith257 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 29 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 32eb051 and 2c94a59.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (2 hunks)

Walkthrough

The pull request focuses on refactoring the GroupChatDetails.spec.tsx test file from Jest to Vitest. The changes involve replacing Jest-specific mocking functions with Vitest equivalents, specifically changing jest.fn() to vi.fn() for mocking functions related to the GroupChatDetails component. Unused imports have been removed, and unnecessary waiting times in test cases have been eliminated, streamlining the test file's structure and functionality. Additionally, Jest-related configurations and scripts have been removed from the project.

Changes

File Change Summary
src/components/GroupChatDetails/GroupChatDetails.spec.tsx - Replaced jest.fn() with vi.fn() for mocking functions
- Removed commented-out imports for fireEvent and waitFor
- Eliminated await wait(10000); lines in test cases
.eslintrc.json - Removed Jest plugin and associated rules
- Deleted "plugin:jest/recommended" from "extends"
- Deleted "jest" from "plugins"
- Deleted "jest/expect-expect": 0 from "rules"
.github/workflows/scripts/countline.py - Removed ".test." from invalid_filenames list
jest-preview.config.ts - Deleted configuration for Jest module name mapping
jest.config.js - Removed entire Jest configuration file
.github/workflows/pull-request.yml - Removed steps for running Jest tests and uploading Jest coverage results

Assessment against linked issues

Objective Addressed Explanation
Replace Jest-specific functions with Vitest equivalents [#3445]
Rename test file to .spec.* suffix [#3445]
Ensure tests pass using npm run test:vitest [#3445] Requires actual test run verification.
Maintain 100% test coverage [#3445] Requires coverage report verification.

Possibly related issues

Possibly related PRs

Suggested labels

refactor, test

Poem

🐰 In the realm of code, a test file transforms,
From Jest's old ways to Vitest's new norms.
Mocks replaced, imports cleaned with care,
A rabbit's refactor beyond compare! 🧪✨


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

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

@syedali237
Copy link
Contributor Author

@varshith257 should I make changes in the global coverage of the jest config file?

Copy link
Contributor

@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 (5)
src/components/GroupChatDetails/GroupChatDetails.spec.tsx (5)

Line range hint 1-19: Optimize test imports for better performance.

Consider using @testing-library/react/pure for testing utilities to improve performance and reduce bundle size.

-import {
-  render,
-  screen,
-  act,
-  fireEvent,
-  waitFor,
-} from '@testing-library/react';
+import { render, screen, act } from '@testing-library/react';
+import { fireEvent, waitFor } from '@testing-library/react/pure';

Line range hint 485-492: Consider reducing waitFor timeout and using better assertions.

The current implementation uses a high timeout (5000ms) which could mask potential issues and make tests slower. Consider:

  1. Reducing the timeout
  2. Using more specific assertions
 await waitFor(
   async () => {
     expect(await screen.findByTestId('editTitleBtn')).toBeInTheDocument();
   },
-  { timeout: 5000 },
+  { timeout: 1000 },
 );

Line range hint 547-554: Consider reducing waitFor timeout and using better assertions.

Similar to the previous test, consider reducing the timeout and using more specific assertions to improve test reliability.

 await waitFor(
   async () => {
     expect(await screen.findByTestId('user')).toBeInTheDocument();
   },
-  { timeout: 5000 },
+  { timeout: 1000 },
 );

Line range hint 591-599: Consider using modern file input testing practices.

The current implementation using Object.defineProperty could be replaced with a more modern approach using the File API and DataTransfer.

-    const fileInput = screen.getByTestId('fileInput');
-    const smallFile = new File(['small-file-content'], 'small-file.jpg');
-    Object.defineProperty(fileInput, 'files', {
-      value: [smallFile],
-    });
-    fireEvent.change(fileInput);
+    const file = new File(['small-file-content'], 'small-file.jpg', { type: 'image/jpeg' });
+    const dataTransfer = new DataTransfer();
+    dataTransfer.items.add(file);
+    const fileInput = screen.getByTestId('fileInput');
+    fireEvent.change(fileInput, { target: { files: dataTransfer.files }});

Line range hint 433-600: Consider organizing tests using describe blocks for better structure.

The test suite could benefit from organizing related tests under describe blocks for better readability and maintenance.

 describe('GroupChatDetails', () => {
+  describe('Rendering', () => {
     it('renders correctly', async () => {
       // ... existing test
     });
+  });
+
+  describe('Chat Title Operations', () => {
     it('edit chat title', async () => {
       // ... existing test
     });
+  });
+
+  describe('User Management', () => {
     it('add user to group chat', async () => {
       // ... existing test
     });
+  });
+
+  describe('Image Operations', () => {
     it('update group chat image', async () => {
       // ... existing test
     });
+  });
 });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3379278 and 9a5dcda.

📒 Files selected for processing (1)
  • src/components/GroupChatDetails/GroupChatDetails.spec.tsx (5 hunks)
🔇 Additional comments (4)
src/components/GroupChatDetails/GroupChatDetails.spec.tsx (4)

434-437: LGTM! Correct migration to Vitest mocks.

The migration from jest.fn() to vi.fn() is implemented correctly.


458-461: LGTM! Correct migration to Vitest mocks.

The migration from jest.fn() to vi.fn() is implemented correctly.


520-523: LGTM! Correct migration to Vitest mocks.

The migration from jest.fn() to vi.fn() is implemented correctly.


567-570: LGTM! Correct migration to Vitest mocks.

The migration from jest.fn() to vi.fn() is implemented correctly.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 27, 2025
@varshith257
Copy link
Member

@syedali237 I think there still 7 test suites i guess from workflow jest exisits can you refactor completely them too and we will remove jest from workflow and adjust vitest here

@syedali237
Copy link
Contributor Author

syedali237 commented Jan 27, 2025

@varshith257 this would be the last test file. I'll just make changes in the jest.config.js, and this should completely migrate our test cases from jest to vitest. Or should I just remove this file as the failing check indicates no tests found?

@varshith257
Copy link
Member

Yes we need to remove all files related to jest and remove it instances in workflows

@varshith257 varshith257 added the ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files label Jan 27, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 27, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 27, 2025
Copy link

codecov bot commented Jan 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.57%. Comparing base (73cf8cd) to head (2c94a59).
Report is 1 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3453       +/-   ##
=====================================================
+ Coverage              1.90%   88.57%   +86.66%     
=====================================================
  Files                   316      338       +22     
  Lines                  8249     8620      +371     
  Branches               1880     1918       +38     
=====================================================
+ Hits                    157     7635     +7478     
+ Misses                 8083      655     -7428     
- Partials                  9      330      +321     

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

@syedali237
Copy link
Contributor Author

I think I should remove these two as well:

  1. Merge Jest and Vitest Coverage Reports
  2. Upload Combined Coverage to Codecov

@varshith257
Copy link
Member

Yes, remove it and change upload coverage strp files to files: ./coverage/vitest/lcov.info

Copy link
Contributor

@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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 20eaead and 32eb051.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
📓 Learnings (1)
📓 Common learnings
Learnt from: bitbard3
PR: PalisadoesFoundation/talawa-admin#2588
File: src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx:145-155
Timestamp: 2024-12-02T04:20:11.745Z
Learning: In PRs focused solely on refactoring test cases from Jest to Vitest, avoid suggesting optimizations or changes outside the migration scope.
🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

258-258: input "gcov_ignore" is not defined in action "codecov/codecov-action@v4". available inputs are "codecov_yml_path", "commit_parent", "directory", "disable_file_fixes", "disable_safe_directory", "disable_search", "dry_run", "env_vars", "exclude", "fail_ci_if_error", "file", "files", "flags", "git_service", "handle_no_reports_found", "job_code", "name", "network_filter", "network_prefix", "os", "override_branch", "override_build", "override_build_url", "override_commit", "override_pr", "plugin", "plugins", "report_code", "root_dir", "slug", "token", "url", "use_legacy_upload_endpoint", "use_oidc", "verbose", "version", "working-directory"

(action)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test Application
🔇 Additional comments (1)
.github/workflows/pull-request.yml (1)

259-259: Verify the coverage file path.

Please verify that the coverage file path ./coverage/vitest/lcov.info is correct after the migration from Jest to Vitest.

Run the following script to verify the coverage file location:

✅ Verification successful

Coverage file path is correctly configured

The path ./coverage/vitest/lcov.info in the workflow file matches exactly with the Vitest configuration:

  • reportsDirectory: './coverage/vitest' is set in vitest.config.ts
  • LCOV reporter is configured in the coverage settings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the Vitest coverage file exists at the specified location

# Test: Check if the coverage file exists
if [ -f "./coverage/vitest/lcov.info" ]; then
    echo "Coverage file exists at the expected location"
    exit 0
else
    echo "Coverage file not found at ./coverage/vitest/lcov.info"
    echo "Please verify the correct path in the workflow configuration"
    exit 1
fi

Length of output: 299


Script:

#!/bin/bash
# Search for Vitest config files and package.json
echo "=== Searching for Vitest config files ==="
fd -e js -e ts -e json "vitest.config|vite.config"

echo -e "\n=== Checking package.json for coverage scripts ==="
if [ -f "package.json" ]; then
    jq '.scripts | with_entries(select(.key | contains("coverage") or contains("test")))' package.json
fi

echo -e "\n=== Checking .gitignore for coverage patterns ==="
if [ -f ".gitignore" ]; then
    grep -i "coverage" .gitignore
fi

echo -e "\n=== Examining Vitest config content ==="
for config in $(fd -e js -e ts -e json "vitest.config|vite.config"); do
    echo -e "\nContent of $config:"
    cat "$config"
done

Length of output: 3108

.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
@varshith257
Copy link
Member

@palisadoes With this our refactoring is done

@palisadoes palisadoes merged commit 0445cb8 into PalisadoesFoundation:develop-postgres Jan 27, 2025
19 checks passed
@palisadoes
Copy link
Contributor

Merged. Thanks for your oversight

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants