Docs per the docs-files-api skill: a 1–2 line @file; what a declaration is or does in JSDoc on it, not in // comments or the file header. Generated-by: Claude Opus 5.5
33 lines
1008 B
TypeScript
33 lines
1008 B
TypeScript
/** @file the tests' main module: the real worker plus a fixed-clock cache. */
|
|
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);
|
|
|
|
/** the private cache's logic on a fixed clock that records each sleep it
|
|
* is asked for (bound as CLOCKED_DO in wrangler.tests.jsonc) */
|
|
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<number[]> {
|
|
return [...this.#sleeps];
|
|
}
|
|
}
|