mirror of
https://github.com/morluto/rea.git
synced 2026-11-14 18:52:48 +00:00
Vitest's expect.poll and vi.waitFor stop after one second by default, a host-speed guess that the project's deadline policy does not see. Under hosted-CI load, kunaProjectConcurrency failed that way twice on unrelated PRs. Another 256 waits relied on the default, and 97 passed literals picked to fit some host. Waits now take as long as their test may run, less the reporting reserve that children already keep. Each Vitest project sets expect.poll's default, and the new waitFor in tests/support/testWait.ts replaces vi.waitFor. Fixture readiness waits (awaitAcknowledgement and the provider process waits) default to the same deadline, and their host-speed literal arguments are removed. One remainingTestDeadline owns the arithmetic for both children and waits. Ten waits whose short timeout was the real check now assert it directly (Kuna version probe, Cutter discovery, doctor and Inspector cancellation, apktool fixture teardown, JADX disconnect): settlement before the production deadline that would otherwise also satisfy the wait, or a deadline pinned beyond every test deadline. The rea/project-wait-deadline lint rule rejects vi.waitFor and explicit expect.poll timeouts. The testing guide and the CI tests audit skill now document the policy. Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
50 lines
2.4 KiB
TypeScript
50 lines
2.4 KiB
TypeScript
import { describe, it } from "vitest";
|
|
import { fileURLToPath } from "node:url";
|
|
import { RuleTester } from "oxlint/plugins-dev";
|
|
import rule from "../../scripts/lint/rules/project-wait-deadline.mjs";
|
|
|
|
RuleTester.describe = describe;
|
|
RuleTester.it = it;
|
|
const tester = new RuleTester({
|
|
languageOptions: { parserOptions: { lang: "ts" } },
|
|
});
|
|
const filename = fileURLToPath(
|
|
new URL("../boundary/ruleControl.test.ts", import.meta.url),
|
|
);
|
|
const vitest = `import { expect, vi } from "vitest";`;
|
|
tester.run("project-wait-deadline", rule, {
|
|
valid: [
|
|
`${vitest} await expect.poll(() => ready).toBe(true);`,
|
|
`${vitest} await expect.poll(() => ready, { interval: 10 }).toBe(true);`,
|
|
`${vitest} await expect.poll(() => ready, { message: "ready" }).toBe(true);`,
|
|
`import { waitFor } from "../support/testWait.js"; await waitFor(() => ready, { interval: 10 });`,
|
|
// Same names that are not Vitest's: a fixture method, or a shadowed local.
|
|
`${vitest} await fixture.vi.waitFor(() => ready, { timeout: 5_000 });`,
|
|
`import { expect } from "vitest"; const vi = { waitFor: (f: Function) => f() }; await vi.waitFor(() => ready);`,
|
|
`import { vi } from "./local.js"; await vi.waitFor(() => ready);`,
|
|
`${vitest} function local(expect: { poll: Function }) { return expect.poll(() => 1, { timeout: 5 }); }`,
|
|
`${vitest} vi.waitUntil;`,
|
|
].map((code) => ({ code, filename })),
|
|
invalid: [
|
|
...[
|
|
`${vitest} await vi.waitFor(() => ready);`,
|
|
`${vitest} await vi.waitFor(() => ready, { interval: 10 });`,
|
|
`import { vi as mocks } from "vitest"; await mocks.waitFor(() => ready);`,
|
|
`import * as vitest from "vitest"; await vitest.vi.waitFor(() => ready);`,
|
|
`${vitest} await vi?.waitFor(() => ready);`,
|
|
].map((code) => ({ code, filename, errors: [{ messageId: "viWaitFor" }] })),
|
|
...[
|
|
`${vitest} await expect.poll(() => ready, { timeout: 5_000 }).toBe(true);`,
|
|
`${vitest} await expect.poll(() => ready, { interval: 10, timeout: limit }).toBe(true);`,
|
|
`${vitest} await expect.poll(() => ready, 5_000).toBe(true);`,
|
|
`${vitest} await expect.poll(() => ready, options).toBe(true);`,
|
|
`import { expect as assert } from "vitest"; await assert.poll(() => ready, { timeout: 5 }).toBe(true);`,
|
|
`import * as vitest from "vitest"; await vitest.expect.poll(() => ready, { "timeout": 5 }).toBe(true);`,
|
|
].map((code) => ({
|
|
code,
|
|
filename,
|
|
errors: [{ messageId: "pollTimeout" }],
|
|
})),
|
|
],
|
|
});
|