Repository navigation
fix(ui-web): skip dev-only diagnostics under Vitest - #1897
Conversation
SummaryThe following content is AI-generated and provides a summary of the pull request: fix(ui-web): Skip
|
There was a problem hiding this comment.
The fix itself is correct and well-scoped — the MODE === 'test' guard cleanly resolves the rAF/teardown race without touching production paths. Two minor issues were flagged in the new test: a redundant afterEach block (already covered by the global restoreMocks: true config), and a vacuous console.warn assertion that can never fail independently of the requestAnimationFrame spy check.
PR Bot Information
Version: 1.22.9
- File Content Strategy: Full file content
- LLM:
anthropic--claude-4.6-sonnet - Correlation ID:
9eb42cd5-dd65-4738-8d92-f6c8237de505 - Event Trigger:
pull_request.opened - Agent Instructions:
| afterEach(() => { | ||
| vi.restoreAllMocks() | ||
| }) |
There was a problem hiding this comment.
Best Practices: afterEach(() => vi.restoreAllMocks()) is redundant
vitest.config.ts already sets restoreMocks: true globally, which automatically restores all spies after each test. This local afterEach block duplicates that behaviour and adds noise.
Consider removing it entirely.
| afterEach(() => { | |
| vi.restoreAllMocks() | |
| }) | |
Double-check suggestion before committing. Edit this comment for amendments.
Please provide feedback on the review comment by checking the appropriate box:
- 🌟 Awesome comment, a human might have missed that.
- ✅ Helpful comment
- 🤷 Neutral
- ❌ This comment is not helpful
| it('should be a no-op under Vitest', () => { | ||
| const rafSpy = vi.spyOn(globalThis, 'requestAnimationFrame') | ||
| const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined) | ||
| validateTokenContract('useTheme', 'tokyo-night-storm') | ||
| expect(rafSpy).not.toHaveBeenCalled() | ||
| expect(warnSpy).not.toHaveBeenCalled() | ||
| }) |
There was a problem hiding this comment.
Logic Error: warnSpy assertion provides no additional coverage
console.warn is only reachable inside the requestAnimationFrame callback, which is never scheduled because the early-return guard fires first. expect(warnSpy).not.toHaveBeenCalled() can never fail independently of expect(rafSpy).not.toHaveBeenCalled() — if rAF is not called, warn cannot be called either. The assertion is therefore vacuous and misleads future readers into thinking console.warn is directly guarded.
The spy on console.warn and its assertion can be removed, leaving only the rafSpy assertion to test the guard behaviour.
| it('should be a no-op under Vitest', () => { | |
| const rafSpy = vi.spyOn(globalThis, 'requestAnimationFrame') | |
| const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined) | |
| validateTokenContract('useTheme', 'tokyo-night-storm') | |
| expect(rafSpy).not.toHaveBeenCalled() | |
| expect(warnSpy).not.toHaveBeenCalled() | |
| }) | |
| it('should be a no-op under Vitest', () => { | |
| const rafSpy = vi.spyOn(globalThis, 'requestAnimationFrame') | |
| validateTokenContract('useTheme', 'tokyo-night-storm') | |
| expect(rafSpy).not.toHaveBeenCalled() | |
| }) | |
Double-check suggestion before committing. Edit this comment for amendments.
Please provide feedback on the review comment by checking the appropriate box:
- 🌟 Awesome comment, a human might have missed that.
- ✅ Helpful comment
- 🤷 Neutral
- ❌ This comment is not helpful
There was a problem hiding this comment.
Applied in 30565ba. console.warn is unreachable when requestAnimationFrame is not called; the rAF spy alone suffices.
27a6dc4 to
c03c125
Compare
c03c125 to
30565ba
Compare
Extract isDev() helper in core/env.ts that returns true only in real DEV (excludes production build and Vitest). Migrate the 7 existing import.meta.env.DEV check sites to the helper. Primary motivation: validateTokenContract schedules a requestAnimationFrame whose body calls console.warn for missing CSS tokens. jsdom does not resolve --color-* tokens, so every theme/skin switch under Vitest 4 queued a console.warn that fired after environment teardown — surfacing as EnvironmentTeardownError on Linux/Node 22; passes on macOS/Node 24. Side effect: silences console.debug noise from storage.ts, providers.ts, ToggleButton.vue under Vitest. dev/build behaviour unchanged. Adds regression test in tests/unit/shared/tokens/contract.test.ts.
30565ba to
8aeb395
Compare
Summary
Extract
isDev()helper inui/web/src/core/env.tsreturningtrueonly when running in real DEV (excludes production build and Vitest). Migrate the 7 existingimport.meta.env.DEVcheck sites to the helper.Root cause
validateTokenContractschedules arequestAnimationFramewhose body callsconsole.warnwhen CSS custom properties are missing. jsdom does not resolve--color-*tokens, so every theme/skin switch under Vitest 4 queued aconsole.warnthat fired after the environment was torn down, surfacing as:Reproducibly fails on Linux/Node 22 in CI; passes on macOS/Node 24 due to rAF timing differences. The
vi.dynamicImportSettled()global drain added in #1893 covers dynamic imports, not rAF callbacks.Scope
Single helper at the canonical source. No production-API change.
core/env.tsisDev()helpershared/tokens/contract.ts:55(rAF leak)if (!import.meta.env.DEV || ...)if (!isDev() || ...)core/storage.ts:8,24,34,59if (import.meta.env.DEV)× 4if (isDev())× 4core/providers.ts:17if (import.meta.env.DEV)if (isDev())main.ts:43if (import.meta.env.DEV)if (isDev())skins/classic/components/buttons/ToggleButton.vue:51if (import.meta.env.DEV)if (isDev())Side effect: silences
console.debug/console.infonoise fromstorage.ts,providers.ts,ToggleButton.vue,main.tsunder Vitest.dev/buildbehaviour unchanged.Verification
ui/web/tests/unit/shared/tokens/contract.test.tsassertsrequestAnimationFrameis not called byvalidateTokenContractunder Vitestpnpm test— 532/532pnpm typecheck,pnpm lint,pnpm build— cleangrep import.meta.env.DEV ui/web/src/— single occurrence, incore/env.ts(single source of truth)PR Checklist
Does this PR introduce a breaking change?