-
-
Notifications
You must be signed in to change notification settings - Fork 845
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: Added Vitest To Requests Screen #2655
Refactor: Added Vitest To Requests Screen #2655
Conversation
WalkthroughThe pull request refactors the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
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
🧹 Outside diff range and nitpick comments (4)
src/screens/Requests/Requests.spec.tsx (4)
29-34
: Enhance localStorage mock implementationWhile the basic mock structure is correct, consider enhancing it with return values and type safety:
-vi.stubGlobal('localStorage', { - getItem: vi.fn(), - setItem: vi.fn(), - clear: vi.fn(), - removeItem: vi.fn(), -}); +vi.stubGlobal('localStorage', { + getItem: vi.fn().mockImplementation((key: string) => null), + setItem: vi.fn().mockImplementation((key: string, value: string) => undefined), + clear: vi.fn().mockImplementation(() => undefined), + removeItem: vi.fn().mockImplementation((key: string) => undefined), +} as Storage);
40-50
: Enhance window.location mock with type safetyConsider adding type safety to the window.location mock:
-Object.defineProperty(window, 'location', { +const mockLocation: Partial<Location> = { + href: 'http://localhost/', + assign: vi.fn(), + reload: vi.fn(), + pathname: '/', + search: '', + hash: '', + origin: 'http://localhost', +}; + +Object.defineProperty(window, 'location', { value: { - href: 'http://localhost/', - assign: vi.fn(), - reload: vi.fn(), - pathname: '/', - search: '', - hash: '', - origin: 'http://localhost', + ...mockLocation, }, + writable: true });
62-69
: Enhance wait utility with timeout handlingThe wait utility is well documented, but consider adding timeout handling for better test reliability:
/** * Utility function to wait for a specified amount of time. * Wraps `setTimeout` in an `act` block for testing purposes. * * @param ms - The duration to wait in milliseconds. Default is 100ms. + * @throws {Error} If the timeout is exceeded * @returns A promise that resolves after the specified time. */ -async function wait(ms = 100): Promise<void> { +async function wait(ms = 100, timeout = 5000): Promise<void> { + const controller = new AbortController(); + const timeoutId = setTimeout(() => controller.abort(), timeout); + await act(() => { return new Promise((resolve) => { - setTimeout(resolve, ms); + const timer = setTimeout(resolve, ms); + controller.signal.addEventListener('abort', () => { + clearTimeout(timer); + throw new Error(`Wait operation timed out after ${timeout}ms`); + }); }); }); + + clearTimeout(timeoutId); }
Line range hint
1-300
: Overall test migration to Vitest looks goodThe migration from Jest to Vitest has been well executed with:
- Proper use of Vitest mocking utilities
- Comprehensive test coverage maintained
- Good async/await handling with act
- Well-structured test cases
Consider adding the following to the test suite:
- Test cleanup in afterEach to reset vi.mocks()
- Explicit typing for mock data
+afterEach(() => { localStorage.clear(); + vi.clearAllMocks(); });
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/screens/Requests/Requests.spec.tsx
(2 hunks)
🔇 Additional comments (1)
src/screens/Requests/Requests.spec.tsx (1)
23-24
: LGTM: Vitest import is correctly added
The import of vi
from 'vitest' is appropriate for the test migration.
We have a policy of unassigning contributors who close PRs without getting validation from our reviewer team. This is because:
Please be considerate of our volunteers' limited time and our desire to improve our code base. This policy is stated as a pinned post in all our Talawa repositories. Our YouTube videos explain why this practice is not acceptable to our Community. Unfortunately, if this continues we will have to close the offending PR and unassign you from the issue. |
@palisadoes Extremely sorry for the act..the only reason for closing of PRs is that it fails many CI tests..Hence , to make the PR pass the CI tests, I have chose to close my PRs and open new one so that it is ready to be merged..this PR is ready to be merged..And I will make sure strictly this won't happen again |
a16118e
into
PalisadoesFoundation:develop-postgres
When there are errors, please make the change in your local repository and push your GitHub origin repo. The PR will be automatically updated. There is no need to close the PR in most cases. |
yeah got it @palisadoes ..just learnt that after this..thanks for your time sir..! |
What kind of change does this PR introduce?
Added Vitest to Requests Screen
Issue Number: 2569
Fixes #2569
Did you add tests for your changes?
Yes
Snapshots/Videos:
If relevant, did you update the documentation?
Summary
Migrated the testing framework to Vitest.
Updated all test files and configurations to be compatible with Vitest's syntax and features.
Have you read the contributing guide?
Yes
Summary by CodeRabbit
vitest
for improved mocking oflocalStorage
andwindow.location
.wait
to facilitate asynchronous testing.