Files
plainleaf/plug-api/lib/memory_cache.test.ts
Zef Hemel 02bd8ed362 Migration Deno -> Node.js
* First pass
* Now using vitest for tests
2026-02-14 22:08:35 +01:00

20 lines
504 B
TypeScript

import { expect, test } from "vitest";
import { ttlCache } from "./memory_cache.ts";
import { sleep } from "./async.ts";
test("Memory cache", async () => {
let calls = 0;
async function expensiveFunction(key: string) {
calls++;
await sleep(1);
return key;
}
expect("key").toEqual(await ttlCache("key", expensiveFunction, 0.01));
expect(1).toEqual(calls);
expect("key").toEqual(await ttlCache("key", expensiveFunction, 0.01));
expect(1).toEqual(calls);
await sleep(10);
});