-
-
Notifications
You must be signed in to change notification settings - Fork 840
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: src/utils/getRefreshToken.test.ts from Jest to Vitest #2913
Refactor: src/utils/getRefreshToken.test.ts from Jest to Vitest #2913
Conversation
WalkthroughThis pull request focuses on refactoring test files from Jest to Vitest, specifically targeting the Changes
Assessment against linked issues
Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command 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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
There was a problem hiding this 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 (2)
src/utils/getRefreshToken.spec.ts (1)
29-33
: Performance caution: use undefined assignment rather than delete
The static analysis tool warns about performance implications of thedelete
operator, especially on highly used objects likewindow
. Consider using an undefined assignment instead to avoid potential performance pitfalls:- delete (window as TestInterfacePartialWindow).location; + (window as TestInterfacePartialWindow).location = undefined;🧰 Tools
🪛 Biome (1.9.4)
[error] 33-33: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
src/screens/OrganizationDashboard/OrganizationDashboard.spec.tsx (1)
Line range hint
379-379
: Minor spelling correction
The test name "should redirectt to / if error occurs" has a slight typo (“redirectt”). Consider correcting it to "redirect".- it('should redirectt to / if error occurs', async () => { + it('should redirect to / if error occurs', async () => {
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/screens/OrganizationDashboard/OrganizationDashboard.spec.tsx
(2 hunks)src/utils/getRefreshToken.spec.ts
(1 hunks)src/utils/getRefreshToken.test.ts
(0 hunks)
💤 Files with no reviewable changes (1)
- src/utils/getRefreshToken.test.ts
🧰 Additional context used
🪛 Biome (1.9.4)
src/utils/getRefreshToken.spec.ts
[error] 33-33: Avoid the delete operator which can impact performance.
Unsafe fix: Use an undefined assignment instead.
(lint/performance/noDelete)
🔇 Additional comments (10)
src/utils/getRefreshToken.spec.ts (8)
1-1
: Meta comment for test environment configuration
The // SKIP_LOCALSTORAGE_CHECK
comment may be referencing a custom rule or linting configuration. Ensure it's documented in the repo guidelines or code comments so future contributors understand its purpose.
2-2
: Vitest import is correct
Good job on replacing Jest imports with Vitest counterparts (describe
, it
, expect
, beforeEach
, vi
).
5-16
: Mocking ApolloClient correctly
The mock setup for mutate
successfully simulates a resolved Promise with expected token data. This is a good approach for testing success paths.
18-24
: Adequate mocking of '@apollo/client'
By returning a custom ApolloClient
that uses your mockApolloClient
, you clearly separate concerns between real and mocked behavior.
37-44
: Local storage mock
The mock object for localStorage
is thorough, covering all standard methods and a few extras. This is good for ensuring comprehensive testing of localStorage usage.
46-52
: Effective use of beforeEach
Resetting mocks before each test ensures independent, repeatable tests. This is consistent with best testing practices.
54-67
: Test for successful refresh
- Verifying that the tokens are updated in local storage.
- Checking that
window.location.reload()
is called. - Ensuring the function returns
true
.
All of these fully validate the success scenario of the refresh function.
69-86
: Test for refresh failure
- Mocking
mutate
to simulate a rejected Promise. - Verifying the function returns
false
and logs the error. - Spying on
console.error
to assert that the error is correctly reported.
These statements thoroughly validate the failure scenario.
src/screens/OrganizationDashboard/OrganizationDashboard.spec.tsx (2)
150-154
: Good async test practice
Waiting for the text to appear before proceeding helps ensure your test synchronizes properly with asynchronous rendering. This approach reduces flakiness and clarifies the test's intent.
163-168
: Flexible matcher usage
Using getByText(/Event 1/i, { exact: false })
is a robust way to handle text variations and potential future changes to event titles. Good call on optimizing for partial matching.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop-postgres #2913 +/- ##
=====================================================
+ Coverage 63.58% 88.00% +24.42%
=====================================================
Files 296 316 +20
Lines 7371 8265 +894
Branches 1610 1866 +256
=====================================================
+ Hits 4687 7274 +2587
+ Misses 2451 779 -1672
+ Partials 233 212 -21 ☔ View full report in Codecov by Sentry. |
431a76a
into
PalisadoesFoundation:develop-postgres
What kind of change does this PR introduce?
Refactor: Migration from Jest to Vitest for test files
Issue Number:
Fixes #2757
Did you add tests for your changes?
Yes. The migrated tests maintain 100% coverage and all tests are passing.
Snapshots/Videos:
Screencast.from.2024-12-26.11-36-48.mp4
If relevant, did you update the documentation?
N/A - This is a test file migration
Summary
This PR migrates
src/utils/getRefreshToken.test.ts
from Jest to Vitest as part of our ongoing migration to Vitest. Additionally, it includes fixes forsrc/screens/OrganizationDashboard/OrganizationDashboard.spec.tsx
which was causing test failures and was approved for modification by Peter Harrison in this conversation.Key changes:
Does this PR introduce a breaking change?
No
Other information
The inclusion of OrganizationDashboard.spec.tsx fixes was discussed and approved by Peter Harrison, who confirmed that while CodeRabbit might flag it, our checks focus on code quality rather than file types.
Have you read the contributing guide?
Yes
Summary by CodeRabbit
OrganizationDashboard
component to ensure accurate loading and verification of upcoming events.refreshToken
function, validating both successful and failed token refresh scenarios.refreshToken
function, streamlining the testing process.