test: simplify cron event call counts

This commit is contained in:
Peter Steinberger
2026-05-08 22:45:16 +01:00
parent cac418d0dd
commit 10e425debe

View File

@@ -41,6 +41,19 @@ describe("CronService interval/cron jobs fire on time", () => {
);
};
const countMainSystemEvents = (
enqueueSystemEvent: ReturnType<typeof vi.fn>,
expectedText: string,
): number => {
let count = 0;
for (const [text] of enqueueSystemEvent.mock.calls) {
if (text === expectedText) {
count++;
}
}
return count;
};
it("fires an every-type main job when the timer fires a few ms late", async () => {
const store = await makeStorePath();
const { cron, enqueueSystemEvent, finished } = createStartedCronServiceWithFinishedBarrier({
@@ -171,10 +184,8 @@ describe("CronService interval/cron jobs fire on time", () => {
const sfRun = await cron.run("legacy-every", "due");
expect(sfRun).toEqual({ ok: true, ran: true });
const sfRuns = enqueueSystemEvent.mock.calls.filter((args) => args[0] === "sf-tick").length;
const minuteRuns = enqueueSystemEvent.mock.calls.filter(
(args) => args[0] === "minute-tick",
).length;
const sfRuns = countMainSystemEvents(enqueueSystemEvent, "sf-tick");
const minuteRuns = countMainSystemEvents(enqueueSystemEvent, "minute-tick");
expect(minuteRuns).toBeGreaterThan(0);
expect(sfRuns).toBeGreaterThan(0);