mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 22:34:32 +00:00
refactor(cron-test): share running-state fixture
This commit is contained in:
@@ -5,6 +5,8 @@ import { afterAll, afterEach, beforeAll, beforeEach, vi } from "vitest";
|
||||
import type { MockFn } from "../test-utils/vitest-mock-fn.js";
|
||||
import type { CronEvent } from "./service.js";
|
||||
import { CronService } from "./service.js";
|
||||
import { createCronServiceState } from "./service/state.js";
|
||||
import type { CronJob } from "./types.js";
|
||||
|
||||
export type NoopLogger = {
|
||||
debug: MockFn;
|
||||
@@ -111,3 +113,26 @@ export function createStartedCronServiceWithFinishedBarrier(params: {
|
||||
});
|
||||
return { cron, enqueueSystemEvent, requestHeartbeatNow, finished };
|
||||
}
|
||||
|
||||
export function createRunningCronServiceState(params: {
|
||||
storePath: string;
|
||||
log: ReturnType<typeof createNoopLogger>;
|
||||
nowMs: () => number;
|
||||
jobs: CronJob[];
|
||||
}) {
|
||||
const state = createCronServiceState({
|
||||
cronEnabled: true,
|
||||
storePath: params.storePath,
|
||||
log: params.log,
|
||||
nowMs: params.nowMs,
|
||||
enqueueSystemEvent: vi.fn(),
|
||||
requestHeartbeatNow: vi.fn(),
|
||||
runIsolatedAgentJob: vi.fn().mockResolvedValue({ status: "ok", summary: "ok" }),
|
||||
});
|
||||
state.running = true;
|
||||
state.store = {
|
||||
version: 1,
|
||||
jobs: params.jobs,
|
||||
};
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user