test: warm cold dynamic imports before the timed cases

Under a full coverage run on every core, a test file's first cold import
(0.6-0.8 s alone) outran the 5 s case timeout and the half-done import
failed every later case in the file: the vitest lane went red in 2 of 5
runs with no defect. A beforeAll warm-up in the 4 files of that pattern;
5 of 5 full runs green after.
This commit is contained in:
2026-10-04 20:09:58 +02:00
parent 0dfb4a984b
commit bc856ab2af
4 changed files with 38 additions and 4 deletions
+10 -1
View File
@@ -3,7 +3,7 @@
// E22 S5: the consented level applied to the tab, and the stream it opens. The module keeps its state
// at module level (what is applied, the queue), so every test imports a fresh copy — and the log
// from that same copy, or it would be reading a different ring.
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
const sent: unknown[][] = [];
const unloaded: unknown[][] = [];
@@ -24,6 +24,15 @@ vi.mock("./api", async () => {
};
});
// Warm the transform cache once (see verifyEntry.dom.test.tsx): the first cold import costs ~0.8 s
// alone and outran the 5 s case timeout under a full coverage run. Transformed code outlives
// vi.resetModules, so each case still gets fresh module instances, only faster.
beforeAll(async () => {
await import("./diagnostics");
await import("./log");
await import("./api");
}, 60_000);
beforeEach(() => {
vi.useFakeTimers();
vi.resetModules();