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:
@@ -4,7 +4,7 @@
|
||||
// consent), never lowers a raised one, tags every event it keeps, and its last seconds reach the
|
||||
// server before Stop. Its own file: `lib/diagnostics` and `lib/log` keep module-level state, so every
|
||||
// test imports fresh copies of both, as diagnostics.dom.test does.
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const sent: { event: string; debug_session_id?: string }[][] = [];
|
||||
|
||||
@@ -45,6 +45,14 @@ const recording = (level: "DEBUG" | "TRACE", minutes = 60, over = {}) => ({
|
||||
...over,
|
||||
});
|
||||
|
||||
// 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");
|
||||
}, 60_000);
|
||||
|
||||
let current: typeof import("./diagnostics") | null = null;
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
|
||||
Reference in New Issue
Block a user