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.
47 lines
2.1 KiB
TypeScript
47 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
|
||
import { eslint } from "./lintProbe.testkit";
|
||
|
||
// `local/input-primitive` (eslint.config.js): every text field is ui/Input, Textarea or InnerInput and
|
||
// every checkbox / slider / colour well a NativeControls primitive (docs/DESIGN.md A4, A6).
|
||
// ~100 hand-styled boxes were swept; this pins that the rule keeping a new one out fires, and where it
|
||
// stands down.
|
||
const RULE = "local/input-primitive";
|
||
|
||
async function hits(source: string, filePath = "src/components/__probe.tsx"): Promise<number> {
|
||
const [result] = await eslint.lintText(source, { filePath });
|
||
return (result?.messages ?? []).filter((m) => m.ruleId === RULE).length;
|
||
}
|
||
|
||
describe("a hand-rolled field", () => {
|
||
// Each new path's first lint makes the type-aware project service load it (0.4–1 s apiece, a repeat
|
||
// ~0): this case lints three, ~1 s idle, past 5 s on a busy machine.
|
||
it(
|
||
"is refused anywhere outside the field primitives, text box or native control",
|
||
{ timeout: 30_000 },
|
||
async () => {
|
||
const text = 'export const A = () => <input className="border px-2" />;\n';
|
||
expect(await hits(text)).toBe(1);
|
||
expect(await hits(text, "src/design-lab/__probe.tsx")).toBe(1);
|
||
// …and in a ui/ composite: the pager's page box is an Input too.
|
||
expect(await hits(text, "src/components/ui/Pager.tsx")).toBe(1);
|
||
expect(await hits("export const B = () => <textarea />;\n")).toBe(1);
|
||
expect(await hits('export const C = () => <input type="checkbox" />;\n')).toBe(1);
|
||
expect(await hits('export const D = () => <input type="range" />;\n')).toBe(1);
|
||
},
|
||
);
|
||
|
||
it("passes in a field primitive, for a file picker, and for the primitives themselves", async () => {
|
||
for (const file of ["Input.tsx", "NativeControls.tsx"])
|
||
expect(await hits("export const E = () => <input />;\n", `src/components/ui/${file}`)).toBe(
|
||
0,
|
||
);
|
||
expect(await hits('export const F = () => <input type="file" hidden />;\n')).toBe(0);
|
||
expect(
|
||
await hits(
|
||
'import { Input } from "./ui/Input";\nexport const G = () => <Input className="w-full" />;\n',
|
||
),
|
||
).toBe(0);
|
||
});
|
||
});
|