You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every test file manually calls vi.clearAllMocks() in beforeEach blocks. Setting clearMocks: true in the Vitest config automates this and removes 32 lines of repeated boilerplate across 10 test files.
Context
The Vitest clearMocks option, when set to true at the config level, automatically calls vi.clearAllMocks() before each test — clearing call counts, recorded arguments, and return values on all mocks. Currently every test file in the repository includes vi.clearAllMocks() in one or more beforeEach callbacks. This is error-prone: a new test file that omits the call risks mock state leaking between tests, producing intermittent failures that are difficult to diagnose. Centralizing the setting eliminates the boilerplate and makes the default safe. Note that clearMocks resets mock state but does not restore original implementations, so existing vi.mock() module replacements are unaffected.
Affected Files
vitest.config.js:4 — Add clearMocks: true to the test configuration object
src/scripts/game.test.js — Remove vi.clearAllMocks() calls from beforeEach blocks
src/scripts/card.test.js — Remove vi.clearAllMocks() calls from beforeEach blocks
src/scripts/deck.test.js — Remove vi.clearAllMocks() calls from beforeEach blocks if present
src/scripts/p2p.test.js — Remove vi.clearAllMocks() calls from beforeEach blocks if present
src/scripts/grab.test.js — Remove vi.clearAllMocks() calls from beforeEach blocks if present
src/scripts/keyboard.test.js — Remove vi.clearAllMocks() calls from beforeEach blocks
src/scripts/token.test.js — Remove vi.clearAllMocks() calls from beforeEach blocks if present
src/scripts/utils.test.js — Remove vi.clearAllMocks() calls from beforeEach blocks if present
src/scripts/sidePanels.test.js — Remove vi.clearAllMocks() calls from beforeEach blocks
src/scripts/deck.integration.test.js — Remove vi.clearAllMocks() call from beforeEach block
Requirements
vitest.config.js includes clearMocks: true in the test object
All manual vi.clearAllMocks() calls in beforeEach blocks are removed from test files
beforeEach blocks that only contained vi.clearAllMocks() and DOM setup retain the DOM setup portion
All tests pass with npm test — no mock state leakage or regressions
Every test file manually calls
vi.clearAllMocks()inbeforeEachblocks. SettingclearMocks: truein the Vitest config automates this and removes 32 lines of repeated boilerplate across 10 test files.Context
The Vitest
clearMocksoption, when set totrueat the config level, automatically callsvi.clearAllMocks()before each test — clearing call counts, recorded arguments, and return values on all mocks. Currently every test file in the repository includesvi.clearAllMocks()in one or morebeforeEachcallbacks. This is error-prone: a new test file that omits the call risks mock state leaking between tests, producing intermittent failures that are difficult to diagnose. Centralizing the setting eliminates the boilerplate and makes the default safe. Note thatclearMocksresets mock state but does not restore original implementations, so existingvi.mock()module replacements are unaffected.Affected Files
vitest.config.js:4— AddclearMocks: trueto thetestconfiguration objectsrc/scripts/game.test.js— Removevi.clearAllMocks()calls frombeforeEachblockssrc/scripts/card.test.js— Removevi.clearAllMocks()calls frombeforeEachblockssrc/scripts/deck.test.js— Removevi.clearAllMocks()calls frombeforeEachblocks if presentsrc/scripts/p2p.test.js— Removevi.clearAllMocks()calls frombeforeEachblocks if presentsrc/scripts/grab.test.js— Removevi.clearAllMocks()calls frombeforeEachblocks if presentsrc/scripts/keyboard.test.js— Removevi.clearAllMocks()calls frombeforeEachblockssrc/scripts/token.test.js— Removevi.clearAllMocks()calls frombeforeEachblocks if presentsrc/scripts/utils.test.js— Removevi.clearAllMocks()calls frombeforeEachblocks if presentsrc/scripts/sidePanels.test.js— Removevi.clearAllMocks()calls frombeforeEachblockssrc/scripts/deck.integration.test.js— Removevi.clearAllMocks()call frombeforeEachblockRequirements
vitest.config.jsincludesclearMocks: truein thetestobjectvi.clearAllMocks()calls inbeforeEachblocks are removed from test filesbeforeEachblocks that only containedvi.clearAllMocks()and DOM setup retain the DOM setup portionnpm test— no mock state leakage or regressionsVerification
Not In Scope
restoreMocks: true— restoring module-level mocks set viavi.mock()would break the existing test architecturejsdomtest environment in this change (covered by issue Centralizejsdomtest environment invitest.config.js#359)beforeEachblocks beyond removing thevi.clearAllMocks()lineEvidence
vitest.config.js:4— Thetestconfig object has noclearMockssetting — defaults tofalse, requiring manual clearing in every test filesrc/scripts/card.test.js:47—vi.clearAllMocks()appears in abeforeEach— one of 12 such calls in this file alonesrc/scripts/game.test.js:49—vi.clearAllMocks()inbeforeEach— repeated in 3 describe blocks in this filesrc/scripts/sidePanels.test.js:45—vi.clearAllMocks()inbeforeEach— repeated in 3 describe blocksArasaka Queue Planning Division.