fix(test): export reset hook and call it in beforeEach for cache isolation

This commit is contained in:
Bilthon
2026-06-02 15:27:19 -05:00
parent bc8611ba7f
commit c47145137d
2 changed files with 10 additions and 3 deletions
+5 -3
View File
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from "bun:test";
import { createMemoryUsageTrackingDriver } from "@routstr/sdk/storage";
import type { UsageTrackingEntry } from "@routstr/sdk/storage";
import type { ClientEntry } from "../../utils/clients";
import { getUsageSummary } from "./usage-summary";
import { getUsageSummary, __resetUsageSummaryCacheForTest } from "./usage-summary";
// ─── Test fixtures ────────────────────────────────────────────────────────────
//
@@ -116,8 +116,10 @@ describe("getUsageSummary", () => {
let driver: ReturnType<typeof createMemoryUsageTrackingDriver>;
beforeEach(async () => {
// Reset module-level cache between tests by creating a fresh driver with a
// distinct entry count each time — the cache key changes.
// Reset the module-level memo cache explicitly so each test starts cold.
// Without this, tests 2-10 would share the cached object from test 1
// (all use the same fixtures → identical cache key → same TTL window).
__resetUsageSummaryCacheForTest();
driver = createMemoryUsageTrackingDriver(ENTRIES);
});
+5
View File
@@ -122,6 +122,11 @@ interface CacheEntry {
let _cache: CacheEntry | null = null;
const CACHE_TTL_MS = 60_000;
/** Clears the module-level memo cache. Intended for use in unit tests only. */
export function __resetUsageSummaryCacheForTest(): void {
_cache = null;
}
// ─── Main builder ─────────────────────────────────────────────────────────────
export async function getUsageSummary(