Repository navigation
test(frontend): lint the Playwright waits that depend on time - #542
Conversation
… MockRoute A fixed delay of a mock races the test: on a slow machine the answer comes before the assertion that needs it in flight, and a short timeout fails before the work ends. api.hold has no time. The six tests that used delayMs now hold the answer and release it at the step that needs it, and the link test of the invite dialog drops its 2 s timeout.
…rLogin, and lint a commit-only navigation A goto with waitUntil 'commit' leaves the load of the app to the next expect, whose 5 s were too short on a slow machine (#502). The three tasks that open a link to the login now call one helper. It waits for the load and for the answer of the login, which the test timeout limits. The lint refuses waitUntil 'commit' in each file of tests/, and its message names the helper.
A wait for an answer or an event starts when it is called, so an await of waitForResponse, waitForRequest, waitForEvent, or a wrapper such as answered() after the action misses an answer that came first. The new typed rule playwright/arm-wait-first reports such an await, and a wait in a const that the next statement awaits. Its message gives the armed form. Three waits on main had this form. The two reconnect tasks of the invites awaited one answer after the other, so they now give the number of the answer to one wait. The Swagger popup test of the stack suite armed its close wait after the login.
A short timeout fails on a slow machine, as the 2 s wait of the invite link did against a 3 s delay of the list. A long one guesses how slow the machine is. The lint refuses a timeout option in tests/, and its message names the armed wait and api.hold. The stack suite keeps its timeouts, because it waits on real IdPs.
The writing-tests skill named a run of the whole functional suite 10 times, about 25 minutes. It now runs the whole suite once, and then --only-changed=main 10 times: each spec that differs from main, and each spec that imports a changed file.
Proof: each new check fails on real codeRun in
|
|
review-gate: passed 9d819450ec91f673f4eb0fd2c7327c6feac2c295 Reviewer: pdstack:thermo-nuclear-review-subagent (opus). No high or medium findings. The low findings that stay open, with reasons:
|
|
PASS+NOTES at head 4eac065 An independent check in a separate detached worktree. All runs are local, because CI has no minutes. Fault forms written as a developer writes them (scratch files in
|
| Form | Check | Result |
|---|---|---|
await page.waitForResponse(...) after a click |
playwright/arm-wait-first |
error, names the armed-const fix |
await answered(...) after a click (sync helper) |
playwright/arm-wait-first |
error |
await Promise.all([answered(), answered()]) after a click |
playwright/arm-wait-first |
error |
await page.waitForEvent('popup') after a click |
playwright/arm-wait-first |
error |
const answer = answered(...) then await answer on the next line (also as const r = await answer) |
playwright/arm-wait-first |
error |
page.goto(url, { waitUntil: 'commit' }) |
no-restricted-syntax |
error, names openAndWaitForLogin |
toBeVisible({ timeout: 2000 }), click({ timeout: 1000 }) |
no-restricted-syntax |
error, names arm-a-wait or api.hold |
api.mock({ ...route, delayMs: 500 }) |
tsc -p tsconfig.tests.json |
TS2353, 'delayMs' does not exist in type 'MockRoute' |
Correct forms: all pass with no false positive. These are an armed wait awaited after the action (with and without its value), an armed Promise.all, Promise.all([wait, action]), an armed popup, const response = await page.goto('/'), goto with waitUntil: 'load', openAndWaitForLogin, a reload with an armed wait, page.request.get, await r.response() on a request in hand, expect.poll, and api.hold(...) in a spec.
Suite at 4eac065
pnpm lint: exit 0.pnpm build: exit 0.pnpm test: 94 files, 880 passed, no type errors.pnpm test:e2e: 370 passed (2.3 min).- Changed specs (
invites,join,session,weather-forecast) with--repeat-each=5: 545 passed, 0 flaky, 0 failed. - Not run:
pnpm test:e2e:stack, so the Swagger popup change ine2e/auth-flows.spec.tswas not run again. The author reports 9 passed on ZeroFactor.
Notes (none blocks the merge)
- The
timeoutban matches any object literal with atimeoutkey that is passed straight to a call. For example,JSON.stringify({ timeout: 30 })or a builder for a DTO with atimeoutfield fails lint. Today no test or app DTO has such a key, so no current code hits this. If a domain field namedtimeoutcomes later, limit the selector to Playwright receivers. - Known gaps, confirmed:
await answered(...).then(...)and anasyncwrapper of a wait both pass the rule. Both are in the review-gate comment. - For a stored wait awaited on the next line with no action before it, the message says "starts after the action before it". The fix it names is still right.
Why
Agents kept writing Playwright tests that pass or fail by the speed of the machine (#502, #490, #494, #507 and more). eslint already refused
waitForTimeoutandsetTimeout. These forms still got through: a mock with a fixed delay, a goto that waits only for the commit and then gives the app load to a 5 s expect, a wait that starts after the action, and a shorttimeoutoption.What changed
MockRoutehas nodelayMs. A test holds an answer withapi.holdand answers it at the step that needs it. tsc refuses a delay.openAndWaitForLogin(page, url)intests/support/answers.tsopens a URL that goes to the login. It waits for the load and for the answer of the login, which the test timeout limits, not a 5 s expect. A lint refuseswaitUntil: 'commit'intests/, and its message names the helper.playwright/arm-wait-first, refuses anawaitof a wait (waitForResponse,waitForRequest,waitForEvent, a sync function that gives a PlaywrightResponseorRequest, or aPromise.allof only waits), and a wait that the next statement awaits. It runs ontests/ande2e/.timeoutoption intests/. Its message names the fix: arm a wait, or hold the answer.delayMsmocks, 3 commit gotos, 2 serial wait loops (now one countinganswered(..., nth)), a 2 s expect, and the Swagger popup close ine2e/auth-flows.spec.ts.--repeat-each=10before a push.Scope
Frontend tests, their lint config, and docs. No app code, no Server code.
Tradeoffs
await answered()would still need the same lint.timeoutban is fortests/only. The stack suite talks to a real IdP and keeps its timeouts.Blast Radius
Lint and test code only. A new test with one of these forms fails
pnpm lint.api.mock({ ..., delayMs })no longer compiles.Verification
Each check fails on real past code: see the proof comment, with SHAs 66b3a8f^, a2fd97e^, and 3b7a3c7. All local (CI has no minutes):
pnpm lint,pnpm build: exit 0.pnpm test: 880 passed (79 in eslint.config.test.js).pnpm test:e2e: 370 passed. Changed specs--repeat-each=10: 1090 passed. The login specs with a plain goto,--repeat-each=5: 325 passed.pnpm test:e2e:stackon an isolated stack with ZeroFactor: 9 passed, 5 skipped, Swagger popup included.