test: fail a test whose code caught and logged a missing mock export

A module mock that leaves out an export the code under test reaches throws
at the call, and where that code catches and logs (a best-effort tail, a
fail-soft read) the test went on green while the path it meant to cover
never ran. The Apple Health import tests mocked the rollup module without
its fold window, so the import tail's rollup fold and cache invalidation
never ran in any of them; four route test files mocked the logging context
or the rollups without what the measurement tail reaches.

Both setup files now watch the console and fail the test in which such a
line was logged. The ECG import test keeps the real rollup module and
stubs only the fold, and the four unit mocks gain what they lacked.
This commit is contained in:
Marc-André Bombeck committed 2026-10-22 23:15:43 +02:00
1 parent 2844088251
commit b09a6d2df8
9 files changed
+107 -4

No files matched your search

@@ -31,7 +31,13 @@ vi.mock("@/lib/jobs/boss-instance", () => ({
getGlobalBoss: vi.fn(() => null),
}));
vi.mock("@/lib/rollups/measurement-rollups", () => ({
// The real module with only the fold stubbed, so the import's tail (its fold
// window, the cache invalidation, the status re-warm) runs as it does in
// production.
vi.mock("@/lib/rollups/measurement-rollups", async (importOriginal) => ({
...(await importOriginal<
typeof import("@/lib/rollups/measurement-rollups")
>()),
recomputeUserRollups: vi.fn(async () => {}),
}));
+5
View File
@@ -1,6 +1,7 @@
import { afterEach, beforeEach, inject, vi } from "vitest";
import { quarantineEntryFor } from "../quarantine/quarantine";
import { watchSwallowedMockErrors } from "../support/swallowed-mock-errors";
import { prepareWorkerDatabase } from "./worker-database";
// Each worker runs against its own clone of the migrated template (see
@@ -30,10 +31,14 @@ process.env.SESSION_SECRET = "integration-test-session-secret-32-bytes";
* the worker BEFORE any application module reads it at import time, and a
* static import here would pull part of the application tree in first.
*/
/** A swallowed "missing mock export" error fails its test (see the module). */
const checkSwallowedMockErrors = watchSwallowedMockErrors();
afterEach(async () => {
const { settleBackgroundTasks } =
await import("@/lib/logging/background-tasks");
await settleBackgroundTasks();
checkSwallowedMockErrors();
});
/** The flaky-test quarantine, as in the unit setup (`vitest.setup.ts`). */