test: tests that assumed an idle machine wait for what they assert, or carry a budget for their work

Under a busy machine (the gate's lanes side by side, 12 busy cores) these went red at random: a press landed while the button was still busy, an answer was settled before it was asked for, a page grew past one wait's budget, a lazy chunk was transformed inside a 1 s wait, focus was taken a frame after the press. They now wait for the condition they depend on, preload the chunks they open, and the tests that do heavy work (whole-repo scans, the type-aware linter, module resets) carry an explicit budget naming that work. The whole suite four times under 12 busy-loop processes: red 4/4 before, 0/4 after.
This commit is contained in:
2026-10-17 01:08:15 +02:00
parent 926e5e9899
commit 5ba5679239
18 changed files with 181 additions and 96 deletions
@@ -6,7 +6,7 @@
//
// i18n is mocked to a key-passthrough; the API is stubbed so nothing reaches out.
import { afterEach, describe, expect, it, vi } from "vitest";
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
vi.mock("react-i18next", async (importOriginal) => {
const actual = await importOriginal<typeof import("react-i18next")>();
@@ -42,6 +42,9 @@ async function failTwice(fail: () => void, message: string) {
fail();
const first = await screen.findByRole("alert");
expect(first.textContent).toBe(message);
// The wizard's Next is busy until its failed step returns (a tick after the message shows), and a
// busy button ignores a press: press again only once nothing on the form says it is working.
await waitFor(() => expect(document.querySelector('[aria-busy="true"]')).toBeNull());
fail();
const second = screen.getByRole("alert");
expect(second.textContent).toBe(message);