refactor(cron-test): share running-state fixture

This commit is contained in:
Peter Steinberger
2026-02-18 16:59:54 +00:00
parent c7831fdf1e
commit 50e5413c19
3 changed files with 35 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ import path from "node:path";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import * as schedule from "./schedule.js";
import { CronService } from "./service.js";
import { createRunningCronServiceState } from "./service.test-harness.js";
import { computeJobNextRunAtMs } from "./service/jobs.js";
import { createCronServiceState, type CronEvent } from "./service/state.js";
import { onTimer } from "./service/timer.js";
@@ -410,20 +411,12 @@ describe("Cron issue regressions", () => {
const timeoutSpy = vi.spyOn(globalThis, "setTimeout");
const store = await makeStorePath();
const now = Date.parse("2026-02-06T10:05:00.000Z");
const state = createCronServiceState({
cronEnabled: true,
const state = createRunningCronServiceState({
storePath: store.storePath,
log: noopLogger,
nowMs: () => now,
enqueueSystemEvent: vi.fn(),
requestHeartbeatNow: vi.fn(),
runIsolatedAgentJob: vi.fn().mockResolvedValue({ status: "ok", summary: "ok" }),
});
state.running = true;
state.store = {
version: 1,
jobs: [createDueIsolatedJob({ id: "due", nowMs: now, nextRunAtMs: now - 1 })],
};
});
await onTimer(state);