/** * @file the tests' main module — their edge: the real worker (whose own * edge supplies the live clock), plus the private cache's logic on a fixed * clock (bound as CLOCKED_DO in wrangler.tests.jsonc). */ import { DiigoCacheLogic } from "../src/cache.js"; import type { CacheEnv } from "../src/cache.js"; export * from "../src/index.js"; export { default } from "../src/index.js"; /** 2099-01-01T00:00:00Z: in the future, so an alarm set by this clock is * never due in real time — tests run it with runDurableObjectAlarm */ export const FIXED_NOW = Date.UTC(2099, 0, 1, 0, 0, 0); /** a fixed clock that records each sleep it is asked for */ export class FixedClockCache extends DiigoCacheLogic { #sleeps: number[] = []; constructor(ctx: DurableObjectState, env: CacheEnv) { const sleeps: number[] = []; super(ctx, env, { now: () => FIXED_NOW, sleep: async (ms) => { sleeps.push(ms); }, }); this.#sleeps = sleeps; } /** the sleeps so far (test hook) */ async sleeps(): Promise { return [...this.#sleeps]; } }