🧪 [testing improvement] Add error path test for getRecentAppIds#42
Conversation
- Export RECENT_APP_STORAGE_KEY and MAX_RECENT_APP_COUNT for testing. - Add comprehensive unit tests for getRecentAppIds and rememberRecentApp. - Cover error paths including invalid JSON, non-array data, and non-integer values in localStorage. Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
📝 WalkthroughWalkthroughThis PR exports two storage-related constants from ChangesRecent App Storage Constants and Testing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/utils/helper.test.ts (1)
111-217: ⚡ Quick winRestore
windowin anafterEachhook to avoid leaking global state.Every test restores
(global as any).window = originalWindowonly at the end of the test body. If any assertion throws first, the restore is skipped, leavingwindowundefined or mocked and corrupting subsequent tests. AnafterEachhook runs even when a test fails and also removes the duplicated restore lines.♻️ Proposed refactor
-import { describe, expect, test, mock } from 'bun:test'; +import { afterEach, describe, expect, test, mock } from 'bun:test';describe('RecentAppIds', () => { const originalWindow = (global as any).window; + afterEach(() => { + (global as any).window = originalWindow; + }); + test('getRecentAppIds should return empty array when window is undefined', () => { (global as any).window = undefined; expect(getRecentAppIds()).toEqual([]); - (global as any).window = originalWindow; });Then drop the trailing
(global as any).window = originalWindow;line from each remaining test.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/helper.test.ts` around lines 111 - 217, Tests set and restore (global as any).window inline which can leak global state on failures; add an afterEach hook that always restores (global as any).window = originalWindow (using the existing originalWindow constant declared in the describe('RecentAppIds') block) and then remove the per-test trailing restores from tests that currently reset window manually (so tests like those exercising getRecentAppIds and rememberRecentApp only set (global as any).window and rely on the shared afterEach to restore it).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/utils/helper.test.ts`:
- Around line 111-217: Tests set and restore (global as any).window inline which
can leak global state on failures; add an afterEach hook that always restores
(global as any).window = originalWindow (using the existing originalWindow
constant declared in the describe('RecentAppIds') block) and then remove the
per-test trailing restores from tests that currently reset window manually (so
tests like those exercising getRecentAppIds and rememberRecentApp only set
(global as any).window and rely on the shared afterEach to restore it).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 337e24d4-ebd8-435f-9128-986db44bf81a
📒 Files selected for processing (2)
src/utils/helper.test.tssrc/utils/helper.ts
🎯 What: The testing gap addressed was the missing error path test for
getRecentAppIdswhenlocalStoragecontains invalid JSON. This PR adds that test case and comprehensive coverage for the entire recent apps feature.📊 Coverage:
windowbeingundefined.localStorage.MAX_RECENT_APP_COUNTlimit.windowbeingundefinedor invalidappIdtypes.✨ Result: Increased reliability and test coverage for the recent apps management utility.
PR created automatically by Jules for task 11677145689250762709 started by @sunnylqm
Summary by CodeRabbit
Tests
Refactor