test: reset leaked cron fake timers

This commit is contained in:
Peter Steinberger
2026-03-22 14:21:12 -07:00
parent 2e246b47b9
commit 2c05e07f68

View File

@@ -73,6 +73,10 @@ export function installCronTestHooks(options: {
}) {
beforeEach(() => {
vi.useFakeTimers();
// Shared unit-thread workers run with isolate disabled, so leaked cron
// timers from a previous file can still sit in the fake-timer queue.
// Clear them before advancing time in the next test file.
vi.clearAllTimers();
vi.setSystemTime(new Date(options.baseTimeIso ?? "2025-12-13T00:00:00.000Z"));
options.logger.debug.mockClear();
options.logger.info.mockClear();
@@ -81,6 +85,7 @@ export function installCronTestHooks(options: {
});
afterEach(() => {
vi.clearAllTimers();
vi.useRealTimers();
});
}