fix(test): add afterEach hook to reset global singletons
Some checks are pending
CI / test (18.x) (push) Waiting to run
CI / test (20.x) (push) Waiting to run
CI / test (22.x) (push) Waiting to run

The test 'should use default maxEvents of 10000' was timing out when run
with the full test suite but passed in isolation. Root cause: global
singleton instances (WorkerAnalytics, CrossReferenceManager, etc.)
retained state across tests in the main 'InMemoryEventStore' describe
block.

Added afterEach hook that calls all available reset* functions to
ensure clean state between tests.

Closes: bf-5u6j
This commit is contained in:
jedarden 2026-05-26 17:39:52 -04:00
parent 15d7915caf
commit 8d75e481c4

View file

@ -3,8 +3,18 @@
*/
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { InMemoryEventStore, getStore, resetStore } from './store.js';
import {
InMemoryEventStore,
getStore,
resetStore,
} from './store.js';
import { LogEvent } from './types.js';
import { resetWorkerAnalytics } from './workerAnalytics.js';
import { resetCrossReferenceManager } from './crossReferenceManager.js';
import { resetHistoricalStore } from './historicalStore.js';
import { resetErrorGroupManager } from './errorGrouping.js';
import { resetRecoveryManager } from './tui/utils/recoveryPlaybook.js';
import { resetCostTracker } from './tui/utils/costTracking.js';
describe('InMemoryEventStore', () => {
let store: InMemoryEventStore;
@ -13,6 +23,16 @@ describe('InMemoryEventStore', () => {
store = new InMemoryEventStore();
});
afterEach(() => {
resetStore();
resetWorkerAnalytics();
resetCrossReferenceManager();
resetHistoricalStore();
resetErrorGroupManager();
resetRecoveryManager();
resetCostTracker();
});
const createEvent = (overrides: Partial<LogEvent> = {}): LogEvent => ({
ts: Date.now(),
worker: 'w-test',