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

Migrated Jest to Vitest for Organizations folder #2626

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CoyoteClear340
Copy link

@CoyoteClear340 CoyoteClear340 commented Dec 9, 2024

What kind of change does this PR introduce?
Migration from Jest to Vitest for the Organizations folder.

Issue Number:

Fixes ##2575

Did you add tests for your changes?
Yes, existing tests were migrated from Jest to Vitest.

Snapshots/Videos:
image

If relevant, did you update the documentation?
No

Summary
This PR migrates all Jest tests in the Organizations folder to Vitest. The changes include:

  • Updating test files to be compatible with Vitest.
  • Ensuring all tests run successfully using npm run test:vitest.

Does this PR introduce a breaking change?
No

Other information

Have you read the contributing guide?
Yes

Summary by CodeRabbit

  • New Features

    • Added support for the chart.js library.
    • Introduced new test scripts for Jest and Vitest, enhancing testing capabilities.
    • Added configuration for Vitest to enable global functions and set up a browser-like environment.
  • Bug Fixes

    • Improved local storage mocking in tests to ensure accurate behavior.
  • Documentation

    • Updated setup file to include custom matchers from @testing-library/jest-dom.
  • Chores

    • Updated various dependencies to their latest versions for improved compatibility.

Copy link

coderabbitai bot commented Dec 9, 2024

Walkthrough

The pull request introduces several modifications primarily to the package.json file, enhancing the testing framework by transitioning from Jest to Vitest. It adds new dependencies and updates existing ones, while also introducing multiple test scripts for Jest and Vitest. Additionally, the testing files have been modified to incorporate Vitest, including the creation of a new configuration file and setup file for Vitest. The changes ensure that the testing environment is compatible with the latest requirements and practices.

Changes

File Change Summary
package.json - Added chart.js.
- Updated @testing-library/jest-dom and @testing-library/react.
- Added @types/react-chartjs-2, @vitest/coverage-v8, and jsdom.
- Replaced old test script with new scripts for Jest and Vitest.
src/screens/UserPortal/Organizations/Organizations.test.tsx - Replaced jest with vitest and added mock for useLocalstorage.
- Minor formatting adjustments.
vitest.config.ts - Introduced Vitest configuration with global settings and environment setup.
vitest.setup.ts - Added import for @testing-library/jest-dom to enhance assertion capabilities in Vitest.

Possibly related issues

Possibly related PRs

Suggested labels

test, ignore-sensitive-files-pr

Suggested reviewers

  • varshith257
  • AVtheking
  • pranshugupta54

Poem

🐰 In the land of code where rabbits play,
New tests were born, hip-hip-hooray!
With Vitest in hand, we hop and cheer,
For every bug fixed, we hold so dear.
Dependencies updated, scripts anew,
In the world of testing, we leap right through! 🎉


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 9, 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: 2

🧹 Outside diff range and nitpick comments (2)
src/screens/UserPortal/Organizations/Organizations.test.tsx (2)

336-338: Consider using beforeEach for mock setup

The mock setup should ideally be within a test lifecycle hook for better test isolation.

Apply this diff to improve the mock setup:

-vi.mock('utils/useLocalstorage', () => ({
-  getItem: vi.fn(() => 'mockUserId'),
-}));
+describe('Testing Organizations Screen [User Portal]', () => {
+  beforeEach(() => {
+    vi.mock('utils/useLocalstorage', () => ({
+      getItem: vi.fn(() => 'mockUserId'),
+    }));
+  });

568-568: Add newline at end of file

Add a newline at the end of the file to follow best practices.

-});
+});
+
🧰 Tools
🪛 eslint

[error] 568-568: Insert

(prettier/prettier)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3d1f1f0 and 21d0987.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • package.json (5 hunks)
  • src/screens/UserPortal/Organizations/Organizations.test.tsx (3 hunks)
  • vitest.config.ts (1 hunks)
  • vitest.setup.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • vitest.setup.ts
  • vitest.config.ts
🧰 Additional context used
🪛 eslint
src/screens/UserPortal/Organizations/Organizations.test.tsx

[error] 568-568: Insert

(prettier/prettier)

🔇 Additional comments (1)
src/screens/UserPortal/Organizations/Organizations.test.tsx (1)

18-18: LGTM: Correct Vitest import

The import of vi from 'vitest' is correctly added to replace Jest's mocking functionality.

Comment on lines +73 to +77
"test": "cross-env NODE_ENV=test jest --env=./scripts/custom-test-env.js --watchAll --coverage",
"test:jest": "cross-env NODE_ENV=test jest --env=./scripts/custom-test-env.js",
"test:vitest": "vitest --run",
"test:vitest:watch": "vitest",
"test:vitest:coverage": "vitest --coverage",
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider consolidating test scripts

The presence of both Jest and Vitest test scripts might cause confusion. Since we're migrating to Vitest, consider:

  1. Deprecating Jest scripts
  2. Renaming Vitest scripts to be the default

Apply this diff to consolidate the scripts:

-    "test": "cross-env NODE_ENV=test jest --env=./scripts/custom-test-env.js --watchAll --coverage",
-    "test:jest": "cross-env NODE_ENV=test jest --env=./scripts/custom-test-env.js",
-    "test:vitest": "vitest --run",
-    "test:vitest:watch": "vitest",
-    "test:vitest:coverage": "vitest --coverage",
+    "test": "vitest --run",
+    "test:watch": "vitest",
+    "test:coverage": "vitest --coverage",
+    "test:jest-legacy": "cross-env NODE_ENV=test jest --env=./scripts/custom-test-env.js"
📝 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
"test": "cross-env NODE_ENV=test jest --env=./scripts/custom-test-env.js --watchAll --coverage",
"test:jest": "cross-env NODE_ENV=test jest --env=./scripts/custom-test-env.js",
"test:vitest": "vitest --run",
"test:vitest:watch": "vitest",
"test:vitest:coverage": "vitest --coverage",
"test": "vitest --run",
"test:watch": "vitest",
"test:coverage": "vitest --coverage",
"test:jest-legacy": "cross-env NODE_ENV=test jest --env=./scripts/custom-test-env.js"

Comment on lines +118 to +119
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Version incompatibility detected with @testing-library/react

The current setup has incompatible versions:

  • @testing-library/[email protected] requires React ^18.0.0 || ^19.0.0
  • Your project uses React ^18.3.1
  • However, @testing-library/react version 16.1.0 appears to be incorrect as the latest major version is 14.x

Recommendation:

  • Downgrade to @testing-library/react ^14.1.2 which is the latest stable version compatible with React 18

The other dependencies (@testing-library/jest-dom, vitest, jsdom) show no direct compatibility issues.

🔗 Analysis chain

Verify version compatibility

The updated testing libraries have significant version changes. Ensure compatibility between:

  • @testing-library/jest-dom ^6.6.3
  • @testing-library/react ^16.1.0
  • @vitest/coverage-v8 ^2.1.8
  • jsdom ^25.0.1
  • vitest ^2.1.8

Also applies to: 129-129, 137-137, 152-152, 158-158


Let me check the React version in package.json to verify compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any reported compatibility issues between these versions
npm info @testing-library/[email protected] peerDependencies
npm info @testing-library/[email protected] peerDependencies
npm info [email protected] peerDependencies

Length of output: 509


Script:

#!/bin/bash
# Check React version in package.json
cat package.json | grep -A 1 '"react":'

Length of output: 103

@palisadoes
Copy link
Contributor

Please fix the failing tests and make sure code rabbit.ai approves your changes

@Cioppolo14
Copy link

@CoyoteClear340 Please fix the failing tests and ensure coderabbit approves your PR.

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.

3 participants