test(core): replace image-cache module mocks with globalThis.fetch spies

Switch `mock.module("../src/image-cache", ...)` stubs in thumbhash, person-detail, colors, and credits tests to `spyOn(globalThis, "fetch")` instead. This avoids the cross-file persistence problem with `mock.module` and tests the real code paths more faithfully.

Update `image-cache.ts` to call `globalThis.fetch` so the spy intercepts it, add `mock.restore()` to the global `afterEach` in `preload.ts`, and set `IMAGE_CACHE_ENABLED=false` in affected tests to avoid disk writes during test runs.
This commit is contained in:
2026-03-15 11:38:35 -04:00
parent d060177c67
commit c201006ca2
6 changed files with 66 additions and 26 deletions
+7 -1
View File
@@ -1,9 +1,15 @@
import { mock } from "bun:test";
import { afterEach, mock } from "bun:test";
import { applyMigrations, testDb } from "@sofa/db/test-utils";
process.env.LOG_LEVEL ??= "error";
mock.module("@sofa/db/client", () => ({
db: testDb,
closeDatabase: () => {},
}));
applyMigrations();
afterEach(() => {
mock.restore();
});