refactor: replace vi.doMock with vi.mock + vi.hoisted#8319
Conversation
- Add ESLint rule to prevent future doMock usage - Refactor versionUtil.test.ts and firebaseAuthStore.test.ts Amp-Thread-ID: https://ampcode.com/threads/T-019bfba6-a757-73bc-8d9f-9716955eabc6 Co-authored-by: Amp <amp@ampcode.com>
📝 WalkthroughWalkthroughThis pull request enhances test patterns by adding an ESLint rule that forbids Changes
Suggested reviewers
✨ Finishing touches
Comment |
🎭 Playwright Tests:
|
🎨 Storybook Build Status✅ Build completed successfully! ⏰ Completed at: 01/26/2026, 07:07:21 PM UTC 🔗 Links🎉 Your Storybook is ready for review! |
Bundle Size ReportSummary
Category Glance Per-category breakdownApp Entry Points — 22.8 kB (baseline 22.8 kB) • ⚪ 0 BMain entry bundles and manifests
Status: 1 added / 1 removed Graph Workspace — 958 kB (baseline 958 kB) • ⚪ 0 BGraph editor runtime, canvas, workflow orchestration
Status: 1 added / 1 removed Views & Navigation — 80.7 kB (baseline 80.7 kB) • ⚪ 0 BTop-level views, pages, and routed surfaces
Status: 9 added / 9 removed Panels & Settings — 466 kB (baseline 466 kB) • 🟢 -8 BConfiguration panels, inspectors, and settings screens
Status: 12 added / 12 removed User & Accounts — 3.94 kB (baseline 3.94 kB) • ⚪ 0 BAuthentication, profile, and account management bundles
Status: 3 added / 3 removed Editors & Dialogs — 2.83 kB (baseline 2.83 kB) • ⚪ 0 BModals, dialogs, drawers, and in-app editors
Status: 2 added / 2 removed UI Components — 33.7 kB (baseline 33.7 kB) • ⚪ 0 BReusable component library chunks
Status: 5 added / 5 removed Data & Services — 3.19 MB (baseline 3.19 MB) • 🔴 +1 BStores, services, APIs, and repositories
Status: 8 added / 8 removed Utilities & Hooks — 25.2 kB (baseline 25.2 kB) • ⚪ 0 BHelpers, composables, and utility bundles
Status: 7 added / 7 removed Vendor & Third-Party — 10.7 MB (baseline 10.7 MB) • ⚪ 0 BExternal libraries and shared vendor chunks
Other — 6.49 MB (baseline 6.49 MB) • 🟢 -192 BBundles that do not match a named category
Status: 34 added / 34 removed |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/stores/firebaseAuthStore.test.ts`:
- Around line 85-99: The shared hoisted mock object mockDistributionTypes (with
properties isCloud and isDesktop) retains mutations between tests causing
order-dependent failures; reset those flags in test setup/teardown by adding a
beforeEach or afterEach that sets mockDistributionTypes.isCloud = false and
mockDistributionTypes.isDesktop = false (or restores original values) so each
test starts with a clean distribution state; update the nested describe(s)
around the token-refresh tests as well to ensure isolation for
mockDistributionTypes.
| const mockDistributionTypes = vi.hoisted(() => ({ | ||
| isCloud: false, | ||
| isDesktop: false | ||
| })) | ||
|
|
||
| vi.mock('@/platform/distribution/types', () => mockDistributionTypes) | ||
|
|
||
| const mockApiKeyStore = vi.hoisted(() => ({ | ||
| getAuthHeader: vi.fn().mockReturnValue(null) | ||
| })) | ||
|
|
||
| vi.mock('@/stores/apiKeyAuthStore', () => ({ | ||
| useApiKeyAuthStore: () => mockApiKeyStore | ||
| })) | ||
|
|
There was a problem hiding this comment.
Reset hoisted distribution flags between tests to avoid leakage.
mockDistributionTypes is a shared object; setting isCloud/isDesktop to true persists beyond the token-refresh tests because vi.resetAllMocks() doesn’t reset plain object state. That can make later tests order-dependent. Please reset these flags in the outer beforeEach (or add an afterEach in the nested describe).
🛠 Suggested fix
beforeEach(() => {
vi.resetAllMocks()
+ mockDistributionTypes.isCloud = false
+ mockDistributionTypes.isDesktop = falseBased on learnings, keep module mocks contained and avoid global mutable state in tests.
Also applies to: 165-180
🤖 Prompt for AI Agents
In `@src/stores/firebaseAuthStore.test.ts` around lines 85 - 99, The shared
hoisted mock object mockDistributionTypes (with properties isCloud and
isDesktop) retains mutations between tests causing order-dependent failures;
reset those flags in test setup/teardown by adding a beforeEach or afterEach
that sets mockDistributionTypes.isCloud = false and
mockDistributionTypes.isDesktop = false (or restores original values) so each
test starts with a clean distribution state; update the nested describe(s)
around the token-refresh tests as well to ensure isolation for
mockDistributionTypes.
Replace
vi.doMockwithvi.mock+vi.hoistedpattern for cleaner test mocking.doMockusageversionUtil.test.tsandfirebaseAuthStore.test.ts┆Issue is synchronized with this Notion page by Unito