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

Refactor from jest to vitest #2483 #3128

Conversation

khushipatil1523
Copy link
Contributor

@khushipatil1523 khushipatil1523 commented Jan 3, 2025

Refactor : src/components/AddPeopleToTag/AddPeopleToTag.test.tsx from Jest to Vitest #2483

What kind of change does this PR introduce?

Refactor

Issue Number: #2483

Fixes #2483

Did you add tests for your changes?

Yes

Snapshots/Videos:
Screenshot 2025-01-03 123309

Summary

Migrated test for ChangeLanguageDropdown.tsx from jest to vitest.

Does this PR introduce a breaking change?

No

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • Configuration

    • Added new environment configuration files with variables for development setup.
    • Updated ESLint configuration to ignore specific files and directories.
  • Development Dependencies

    • Updated ESLint and related plugins to newer versions.
  • Testing

    • Migrated test files from Jest to Vitest.
    • Updated mocking approach in test suites.

Copy link
Contributor

coderabbitai bot commented Jan 3, 2025

Walkthrough

This pull request introduces several configuration and testing-related changes to the Talawa-admin project. The modifications include creating new environment configuration example files (.env_BACKUP_322.example, .env_LOCAL_322.example, .env_REMOTE_322.example) with standardized environment variables, updating the ESLint configuration to ignore specific files, upgrading various development dependencies in package.json, and refactoring the AddPeopleToTag.spec.tsx test file from Jest to Vitest.

Changes

File Change Summary
.env_*_322.example Added new environment configuration files with variables like PORT, REACT_APP_TALAWA_URL, REACT_APP_USE_RECAPTCHA, REACT_APP_RECAPTCHA_SITE_KEY, REACT_APP_BACKEND_WEBSOCKET_URL, and ALLOW_LOGS
eslint.config.js Added new default export with ignores property to exclude specific files and directories from linting
package.json Updated development dependencies: eslint, eslint-plugin-jest, eslint-plugin-react, and eslint-plugin-tsdoc
src/components/AddPeopleToTag/AddPeopleToTag.spec.tsx Migrated from Jest to Vitest, replacing jest.mock with vi.mock and updating test function syntax

Assessment against linked issues

Objective Addressed Explanation
Refactor AddPeopleToTag.test.tsx from Jest to Vitest [#2483]
Rename test file from .test.tsx to .spec.tsx [#2483]
Ensure tests pass using npm run test:vitest [#2483] Requires additional verification during testing
Maintain 100% test coverage [#2483] Requires code coverage verification

Possibly related issues

Possibly related PRs

Suggested labels

refactor, test

Suggested reviewers

  • pranshugupta54
  • varshith257

Poem

🐰 A Rabbit's Ode to Testing Delight
From Jest to Vitest, our code takes flight,
Mocks and tests now shine so bright,
Configuration files, neat and clean,
Our development process, a well-oiled machine!
Hop, hop, hooray for code so right! 🚀


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

github-actions bot commented Jan 3, 2025

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

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

🧹 Nitpick comments (1)
src/components/AddPeopleToTag/AddPeopleToTag.spec.tsx (1)

184-184: Typographical nit: "searchs" → "searches".

The test descriptions contain a minor misspelling. Consider renaming them to maintain clarity:

-  it('searchs for tags where the firstName matches...', async () => {
+  it('searches for tags where the firstName matches...', async () => {

-  it('searchs for tags where the lastName matches...', async () => {
+  it('searches for tags where the lastName matches...', async () => {

Also applies to: 217-217

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2215c0a and b90fa0b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • .env_BACKUP_322.example (1 hunks)
  • .env_LOCAL_322.example (1 hunks)
  • .env_REMOTE_322.example (1 hunks)
  • eslint.config.js (1 hunks)
  • package.json (1 hunks)
  • src/components/AddPeopleToTag/AddPeopleToTag.spec.tsx (11 hunks)
✅ Files skipped from review due to trivial changes (3)
  • eslint.config.js
  • .env_LOCAL_322.example
  • .env_REMOTE_322.example
🧰 Additional context used
📓 Learnings (1)
src/components/AddPeopleToTag/AddPeopleToTag.spec.tsx (1)
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.
🔇 Additional comments (5)
src/components/AddPeopleToTag/AddPeopleToTag.spec.tsx (4)

2-2: Switched from Jest to Vitest.

The import of { vi, expect, describe, it } from 'vitest' is correctly placed. Good job keeping the test framework usage consistent throughout the spec file.


38-41: Usage of vi.mock is consistent.

Mocking react-toastify with vi.mock aligns well with Vitest's approach. This change looks correct.


118-125: Mocking react-router-dom with Vitest.

The approach of partially importing and then mocking useParams is a standard Vitest pattern. This transition away from jest.mock is applied correctly.


127-128: Clearing mocks before each test run.

Calling vi.clearAllMocks() in beforeEach ensures a clean state for every test. Excellent practice.

package.json (1)

142-148: Dependencies upgraded successfully.

Upgrading ESLint and related plugins appears consistent with the transition to the new test setup. No issues detected.

.env_BACKUP_322.example Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.52%. Comparing base (c5a3000) to head (ff3bf5b).
Report is 66 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3128       +/-   ##
=====================================================
+ Coverage             33.14%   89.52%   +56.38%     
=====================================================
  Files                   299      322       +23     
  Lines                  7429     8455     +1026     
  Branches               1624     1844      +220     
=====================================================
+ Hits                   2462     7569     +5107     
+ Misses                 4762      655     -4107     
- Partials                205      231       +26     

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

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 3, 2025
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: 2

🧹 Nitpick comments (3)
.env_BACKUP_322.example (3)

11-11: Add example value for REACT_APP_TALAWA_URL.

To help developers understand the expected format, provide an example value.

-REACT_APP_TALAWA_URL=
+REACT_APP_TALAWA_URL=http://localhost:4000/graphql

17-17: Enhance security-related documentation.

For security-sensitive configurations (RECAPTCHA), consider:

  1. Adding a comment warning users not to commit actual keys
  2. Providing a dummy/example key format
-REACT_APP_USE_RECAPTCHA=
+REACT_APP_USE_RECAPTCHA=  # yes/no - DO NOT COMMIT ACTUAL CONFIGURATION
 
 # If you are using Google Recaptcha, i.e., REACT_APP_USE_RECAPTCHA=yes, read the following steps
 # Get the google recaptcha site key from google recaptcha admin or https://www.google.com/recaptcha/admin/create 
 # from here for reCAPTCHA v2 and "I'm not a robot" Checkbox, and paste the key here.
 # Note: In domains, fill localhost 
 
-REACT_APP_RECAPTCHA_SITE_KEY=
+REACT_APP_RECAPTCHA_SITE_KEY=  # Format: 6LcXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - DO NOT COMMIT ACTUAL KEY

Also applies to: 24-24


29-31: Standardize the ALLOW_LOGS configuration.

The current documentation for ALLOW_LOGS could be improved:

  1. Inconsistent casing ("YES" vs typical boolean values)
  2. Typos and formatting in the comment
-# If you want to logs Compiletime and Runtime error , warning and info write YES or if u want to  
-# keep the console clean leave it blank
-ALLOW_LOGS=
+# Enable logging of compile-time and runtime errors, warnings, and info
+# Set to 'true' to enable logging, leave blank to keep the console clean
+ALLOW_LOGS=  # true/false
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b90fa0b and ff3bf5b.

📒 Files selected for processing (1)
  • .env_BACKUP_322.example (1 hunks)

Comment on lines +1 to +31
# 👋 Welcome, we're glad you're setting up an installation of Talawa-admin. Copy this
# file to .env or set the variables in your local environment manually.


# Custom port number for the talawa-admin development server to run on. Default is 4321.

PORT=4321

# Run Talawa-api locally in your system, and put its url into the same.

REACT_APP_TALAWA_URL=

# Do you want to setup and use "I'm not a robot" Checkbox (Google Recaptcha)?
# If no, leave blank, else write yes
# Example: REACT_APP_USE_RECAPTCHA=yes

REACT_APP_USE_RECAPTCHA=

# If you are using Google Recaptcha, i.e., REACT_APP_USE_RECAPTCHA=yes, read the following steps
# Get the google recaptcha site key from google recaptcha admin or https://www.google.com/recaptcha/admin/create
# from here for reCAPTCHA v2 and "I'm not a robot" Checkbox, and paste the key here.
# Note: In domains, fill localhost

REACT_APP_RECAPTCHA_SITE_KEY=

# has to be inserted in the env file to use plugins and other websocket based features.
REACT_APP_BACKEND_WEBSOCKET_URL=ws://localhost:4000/graphql

# If you want to logs Compiletime and Runtime error , warning and info write YES or if u want to
# keep the console clean leave it blank
ALLOW_LOGS=
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Rename the file to follow standard conventions.

The filename .env_BACKUP_322.example appears to be a merge conflict artifact (containing "BACKUP" and "322"). This should be renamed to follow the standard .env.example convention for environment template files.

Apply this change:

  1. Rename the file from .env_BACKUP_322.example to .env.example
  2. Remove any duplicate .env_LOCAL_322.example and .env_REMOTE_322.example files if they contain the same configuration

Comment on lines +26 to +27
# has to be inserted in the env file to use plugins and other websocket based features.
REACT_APP_BACKEND_WEBSOCKET_URL=ws://localhost:4000/graphql
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

WebSocket URL format inconsistency found in environment files

There is an inconsistency in the trailing slash of the WebSocket URLs across the environment files:

  • With trailing slash /:
    • .env.example: ws://localhost:4000/graphql/
    • .env_LOCAL_322.example: ws://localhost:4000/graphql/
  • Without trailing slash:
    • .env_BACKUP_322.example: ws://localhost:4000/graphql
    • .env_REMOTE_322.example: ws://localhost:4000/graphql

The format should be standardized across all environment files. Based on the INSTALLATION.md examples, the format with the trailing slash (ws://localhost:4000/graphql/) appears to be the intended format.

🔗 Analysis chain

Verify WebSocket URL format consistency.

The WebSocket URL format should be consistent across all environment files. Let's verify this:


Let me gather more information to check the actual .env files.


Let me try again with the hidden flag.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for inconsistencies in WebSocket URL format across env files
echo "Checking WebSocket URL format in env files..."
rg -l "REACT_APP_BACKEND_WEBSOCKET_URL" | while read -r file; do
  echo "=== $file ==="
  rg "REACT_APP_BACKEND_WEBSOCKET_URL" "$file"
done

Length of output: 2122


Script:

#!/bin/bash
# Check all env files and examples for WebSocket URL format
echo "Checking all .env* files..."
fd -t f "^\.env" | while read -r file; do
  echo "=== $file ==="
  grep "REACT_APP_BACKEND_WEBSOCKET_URL" "$file" || true
done

Length of output: 306


Script:

#!/bin/bash
# Check all env files and examples for WebSocket URL format
echo "Checking all .env* files..."
fd -H -t f "^\.env" | while read -r file; do
  echo "=== $file ==="
  grep "REACT_APP_BACKEND_WEBSOCKET_URL" "$file" || true
done

Length of output: 1063

@palisadoes
Copy link
Contributor

  1. Closing. you have submitted too many files that are irrelevant to the issue.
  2. Please resubmit with only the requested file updated

@palisadoes palisadoes closed this Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants