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/screens/PageNotFound/PageNotFound.test.tsx from Jest to Vitest #2568 #2590

Conversation

dev-mayanktiwari
Copy link

@dev-mayanktiwari dev-mayanktiwari commented Dec 2, 2024

What kind of change does this PR introduce?

Refactoring

Issue Number:

Fixes #2568

Did you add tests for your changes?

Yes

Snapshots/Videos:

image

If relevant, did you update the documentation?

Not required

Summary

Refactored src/screens/PageNotFound/PageNotFound.test.tsx from Jest to Vitest

Does this PR introduce a breaking change?

Other information

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Added a new dependency for improved testing capabilities.
  • Bug Fixes

    • Enhanced test suite for the PageNotFound component to ensure proper rendering for different user roles.
  • Chores

    • Updated several dependencies to their latest versions for better performance and compatibility.

Copy link

coderabbitai bot commented Dec 2, 2024

Walkthrough

The pull request introduces updates to the package.json file for the talawa-admin project, including the addition of a new dependency (@testing-library/dom) and updates to existing dependencies and resolutions. Additionally, it modifies the test suite for the PageNotFound component to transition from Jest to Vitest, ensuring compatibility with the new testing framework.

Changes

File Path Change Summary
package.json - Added dependency: @testing-library/dom at ^10.4.0
- Updated vitest from ^2.1.5 to ^2.1.8
- Updated resolutions for graphql, @apollo/client, and @types/react
- Set Node.js engine requirement to >=20.x
src/screens/PageNotFound/PageNotFound.spec.tsx - Imported describe, test, and expect from vitest
- Updated test cases to use setItem from useLocalStorage

Assessment against linked issues

Objective Addressed Explanation
Replace Jest-specific functions and mocks with Vitest equivalents (#2568)
Ensure all tests in src/screens/PageNotFound pass after migration (#2568)
Maintain the test coverage for the file as 100% after migration (#2568)

Possibly related issues

Possibly related PRs

Suggested labels

refactor, test

Suggested reviewers

  • pranshugupta54
  • varshith257

Poem

🐇 In the land of code so bright,
A rabbit hops with pure delight.
Dependencies updated, tests refined,
With Vitest now, our paths aligned.
Hooray for changes, let’s all cheer,
For a cleaner codebase, year after year! 🐇


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.

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 Dec 2, 2024

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

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congratulations on making your first PR! 🎊 If you haven't already, check out our Contributing Guidelines and PR Reporting Guidelines to ensure that you are following our guidelines for contributing and creating PR.

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)
src/screens/PageNotFound/PageNotFound.spec.tsx (1)

Line range hint 15-41: Consider adding cleanup between tests

While the first test case looks good, it's recommended to clear any localStorage values between tests to prevent potential interference. Consider adding a cleanup step.

 describe('Testing Page not found component', () => {
+  afterEach(() => {
+    // Clear localStorage between tests
+    localStorage.clear();
+  });

   test('Component should be rendered properly for User', () => {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c2630ae and e3f963d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json (2 hunks)
  • src/screens/PageNotFound/PageNotFound.spec.tsx (2 hunks)
🔇 Additional comments (3)
src/screens/PageNotFound/PageNotFound.spec.tsx (2)

11-11: LGTM: Vitest imports correctly added

The migration to Vitest imports looks correct. The test structure maintains compatibility with the new testing framework while preserving the existing test cases.


Line range hint 42-60: Verify test isolation and coverage

The test cases appropriately verify different user scenarios and component text elements. However, let's verify the test coverage remains at 100% as specified in the PR objectives.

✅ Verification successful

Test coverage is complete and properly isolated

The test suite comprehensively covers all code paths and rendering scenarios of the PageNotFound component:

  • Tests both user scenarios (regular user and admin) by manipulating the AdminFor localStorage value
  • Verifies all rendered text elements including the conditional ones (Talawa User vs Talawa Admin Portal)
  • Checks the presence of the 404 message, error text, and navigation button
  • Validates the component's behavior with proper test isolation using BrowserRouter, Redux Provider, and i18n setup

The test implementation matches the component's functionality completely, with no uncovered code paths.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test coverage for PageNotFound component
# Expected: Coverage should be 100%

# Run Vitest coverage for this specific file
npx vitest run src/screens/PageNotFound/PageNotFound.spec.tsx --coverage

Length of output: 168


Script:

#!/bin/bash
# Let's analyze the test file and component to verify test coverage manually
# First, let's see the component implementation
cat src/screens/PageNotFound/PageNotFound.tsx

# Then, let's see the test file
cat src/screens/PageNotFound/PageNotFound.spec.tsx

Length of output: 4278

package.json (1)

26-26: Verify @testing-library/dom compatibility

The addition of @testing-library/dom is appropriate for the test migration. However, let's verify there are no conflicts with other testing libraries.

✅ Verification successful

No compatibility issues with @testing-library/dom

The codebase already uses the Testing Library ecosystem extensively with @testing-library/react and @testing-library/jest-dom in devDependencies. The addition of @testing-library/dom v10.4.0 is compatible with the existing testing setup, as evidenced by:

  • Extensive usage of Testing Library in 100+ test files
  • Compatible versions: React Testing Library v16.0.1 and Jest DOM v6.6.3
  • No conflicting peer dependencies found
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential conflicts between testing libraries
# Expected: No dependency conflicts

# Check for peer dependency conflicts
npm ls @testing-library/dom @testing-library/react @testing-library/jest-dom 2>/dev/null || true

Length of output: 136


Script:

#!/bin/bash
# Let's check the actual package.json content to see testing library dependencies
cat package.json | jq '.dependencies, .devDependencies' 2>/dev/null

# Also check if there are any existing testing library imports in the codebase
rg --type js --type ts "@testing-library/(dom|react|jest-dom)" -l

Length of output: 13904

@@ -156,7 +157,7 @@
"sass": "^1.80.7",
"tsx": "^4.19.1",
"vite-plugin-svgr": "^4.2.0",
"vitest": "^2.1.5",
"vitest": "^2.1.8",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Review dependency version downgrades

There are concerning version downgrades in the resolutions:

  • @apollo/client from ^3.11.8 to ^3.4.0-beta.19
  • @types/react from ^18.3.12 to 17.0.2
  • graphql from ^16.9.0 to ^16.5.0

These downgrades might introduce compatibility issues or miss important bug fixes.

Please provide justification for these downgrades or consider maintaining the newer versions.

Also applies to: 164-167

@palisadoes
Copy link
Contributor

There isn’t an issue assigned to you for this PR. Please follow the guidelines in our PR_GUIDELINES.md file. We have the procedures in place so that everyone has a fair chance of contributing. I will be closing this pull request. Please follow the procedures and resubmit when ready. 

@palisadoes palisadoes closed this Dec 2, 2024
@dev-mayanktiwari dev-mayanktiwari deleted the refactor/2568-jest_to_vitest_pagenotfound branch December 2, 2024 20:17
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