Skip to content

Commit 1d26632

Browse files
DrJKLampagent
andauthored
test: clear local storage before each test (#15053)
## Summary Child of #15052. Give every test a clean localStorage baseline through the shared Vitest setup. ```ts beforeEach(() => { globalThis.localStorage?.clear() }) ``` The optional access keeps the shared setup compatible with the website and object-parser projects, which use Vitest's Node environment and do not expose localStorage. ## Audit results | Classification | Calls | Outcome | |---|---:|---| | Test-boundary setup/teardown | 50 | Removed as globally redundant | | Intra-test fast-check run isolation | 1 | Retained | | **Total audited** | **51** | **30 test files** | The retained call separates generated command sequences and shrink attempts inside a single Vitest test. A global `beforeEach` cannot replace it. The cleanup also removes empty hooks, stale comments, and unused lifecycle imports. Net diff: 10 additions and 106 deletions across 31 files. ## Validation | Project | Test files | Passed | Skipped | Failed | |---|---:|---:|---:|---:| | Root | 1,159 | 15,896 | 8 | 0 | | Desktop UI | 16 | 125 | 0 | 0 | | Website | 41 | 387 | 0 | 0 | | Object info parser | 4 | 33 | 0 | 0 | Also passed: - `pnpm typecheck` - `pnpm lint` (six pre-existing warnings, zero errors) - oxfmt and type-aware Oxlint on all changed files - pre-push `pnpm knip --cache` Co-authored-by: Amp <amp@ampcode.com>
1 parent 2bdf764 commit 1d26632

31 files changed

Lines changed: 10 additions & 106 deletions

src/components/TopMenuSection.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ function createComfyActionbarStub(actionbarTarget: HTMLElement) {
196196

197197
describe('TopMenuSection', () => {
198198
beforeEach(() => {
199-
localStorage.clear()
200199
mockData.isLoggedIn = false
201200
mockData.setShowConflictRedDot(false)
202201
})

src/components/actionbar/ComfyActionbar.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ const renderActionbar = (showRunProgressBar: boolean) => {
6363
describe('ComfyActionbar', () => {
6464
beforeEach(() => {
6565
i18n.global.locale.value = 'en'
66-
localStorage.clear()
6766
})
6867

6968
it('teleports inline progress when run progress bar is enabled', async () => {

src/composables/maskeditor/useBrushPersistence.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const STORAGE_KEY = 'maskeditor_brush_settings'
2828

2929
beforeEach(() => {
3030
setActivePinia(createTestingPinia({ stubActions: false }))
31-
localStorage.clear()
3231
})
3332

3433
describe('loadAndApply', () => {

src/composables/useFeatureFlags.test.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,6 @@ describe('useFeatureFlags', () => {
235235
})
236236

237237
describe('dev override via localStorage', () => {
238-
afterEach(() => {
239-
localStorage.clear()
240-
})
241-
242238
it('resolveFlag returns localStorage override over remoteConfig and server value', () => {
243239
vi.mocked(api.getServerFeature).mockReturnValue(false)
244240
localStorage.setItem('ff:model_upload_button_enabled', 'true')
@@ -301,7 +297,6 @@ describe('useFeatureFlags', () => {
301297
remoteConfig.value = {}
302298
cachedBillingControlEnabled.value = undefined
303299
cachedV1PaymentRecovery.value = undefined
304-
localStorage.clear()
305300
})
306301

307302
afterEach(() => {
@@ -310,7 +305,6 @@ describe('useFeatureFlags', () => {
310305
remoteConfig.value = {}
311306
cachedBillingControlEnabled.value = undefined
312307
cachedV1PaymentRecovery.value = undefined
313-
localStorage.clear()
314308
})
315309

316310
it('returns the cached session value during the auth window', () => {
@@ -359,10 +353,6 @@ describe('useFeatureFlags', () => {
359353
})
360354

361355
describe('signupTurnstileMode', () => {
362-
afterEach(() => {
363-
localStorage.clear()
364-
})
365-
366356
it('falls back to the server feature flag with default off', () => {
367357
vi.mocked(api.getServerFeature).mockImplementation(
368358
(path, defaultValue) => {
@@ -436,7 +426,6 @@ describe('useFeatureFlags', () => {
436426
afterEach(() => {
437427
vi.mocked(distributionTypes).isCloud = false
438428
remoteConfig.value = {}
439-
localStorage.clear()
440429
})
441430

442431
it('is disabled outside the cloud distribution', () => {
@@ -466,10 +455,6 @@ describe('useFeatureFlags', () => {
466455
})
467456

468457
describe('unifiedCloudAuthEnabled', () => {
469-
afterEach(() => {
470-
localStorage.clear()
471-
})
472-
473458
it('reads the unified_cloud_auth server feature when set', () => {
474459
vi.mocked(api.getServerFeature).mockImplementation(
475460
(path, defaultValue) => {
@@ -497,7 +482,6 @@ describe('useFeatureFlags', () => {
497482
vi.mocked(distributionTypes).isCloud = false
498483
remoteConfigState.value = 'unloaded'
499484
cachedBillingControlEnabled.value = undefined
500-
localStorage.clear()
501485
remoteConfig.value = {}
502486
})
503487

src/composables/useRunButtonTelemetry.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import {
4545

4646
describe('useRunButtonTelemetry', () => {
4747
beforeEach(() => {
48-
localStorage.clear()
4948
state.telemetry.trackRunButton.mockClear()
5049
state.mode.value = 'graph'
5150
state.isAppMode.value = false

src/platform/cloud/subscription/components/CreditsTile.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ describe('CreditsTile', () => {
209209
state.type = 'workspace'
210210
state.customerEventsError = null
211211
mockIsCloud.value = true
212-
localStorage.clear()
213212
})
214213

215214
it('renders the total balance (cents converted to credits) with the remaining suffix', () => {

src/platform/surveys/ErrorPanelSurveyCta.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { render, screen, within } from '@testing-library/vue'
22
import userEvent from '@testing-library/user-event'
3-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
3+
import { beforeEach, describe, expect, it, vi } from 'vitest'
44
import { nextTick, ref } from 'vue'
55

66
const FEATURE_USAGE_KEY = 'Comfy.FeatureUsage'
@@ -82,7 +82,6 @@ describe('ErrorPanelSurveyCta', () => {
8282
}
8383

8484
beforeEach(() => {
85-
localStorage.clear()
8685
vi.resetModules()
8786
mockOpen.mockReset()
8887

@@ -97,10 +96,6 @@ describe('ErrorPanelSurveyCta', () => {
9796
}
9897
})
9998

100-
afterEach(() => {
101-
localStorage.clear()
102-
})
103-
10499
async function renderComponent() {
105100
const { default: ErrorPanelSurveyCta } =
106101
await import('./ErrorPanelSurveyCta.vue')

src/platform/surveys/NightlySurveyPopover.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { render, screen } from '@testing-library/vue'
22
import userEvent from '@testing-library/user-event'
3-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
3+
import { beforeEach, describe, expect, it, vi } from 'vitest'
44
import { nextTick } from 'vue'
55
import { createI18n } from 'vue-i18n'
66

@@ -44,18 +44,13 @@ describe('NightlySurveyPopover', () => {
4444
}
4545

4646
beforeEach(() => {
47-
localStorage.clear()
4847
vi.resetModules()
4948

5049
mockIsNightly.value = true
5150
mockIsCloud.value = false
5251
mockIsDesktop.value = false
5352
})
5453

55-
afterEach(() => {
56-
localStorage.clear()
57-
})
58-
5954
async function renderComponent(
6055
config = defaultConfig,
6156
eventHandlers: Record<string, ReturnType<typeof vi.fn>> = {}

src/platform/surveys/useFeatureUsageTracker.test.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
1+
import { describe, expect, it, vi } from 'vitest'
22

33
import { useFeatureUsageTracker } from './useFeatureUsageTracker'
44

55
const STORAGE_KEY = 'Comfy.FeatureUsage'
66

77
describe('useFeatureUsageTracker', () => {
8-
beforeEach(() => {
9-
localStorage.clear()
10-
})
11-
12-
afterEach(() => {
13-
localStorage.clear()
14-
})
15-
168
it('initializes with zero count for new feature', () => {
179
const { useCount } = useFeatureUsageTracker('test-feature-1')
1810

src/platform/surveys/useSurveyEligibility.test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
1+
import { beforeEach, describe, expect, it, vi } from 'vitest'
22

33
import { useSurveyEligibility } from './useSurveyEligibility'
44

@@ -30,17 +30,11 @@ describe('useSurveyEligibility', () => {
3030
}
3131

3232
beforeEach(() => {
33-
localStorage.clear()
34-
3533
mockDistribution.isNightly = true
3634
mockDistribution.isCloud = false
3735
mockDistribution.isDesktop = false
3836
})
3937

40-
afterEach(() => {
41-
localStorage.clear()
42-
})
43-
4438
function setFeatureUsage(featureId: string, useCount: number) {
4539
const existing = JSON.parse(localStorage.getItem(FEATURE_USAGE_KEY) ?? '{}')
4640
existing[featureId] = {

0 commit comments

Comments
 (0)