|
| 1 | +# W-22972995 — LWC E2E: replace waitForTimeout in lwcRunTests Test Explorer helper |
| 2 | + |
| 3 | +## Context |
| 4 | + |
| 5 | +- File: `packages/salesforcedx-vscode-lwc/test/playwright/specs/lwcRunTests.desktop.spec.ts` |
| 6 | +- `openAndRefreshTestExplorer` (lines 73-79): focus Test Explorer → `waitForTimeout(2000)` → `Test: Refresh Tests` → `waitForTimeout(3000)` |
| 7 | +- 5s too short on slow Windows runners → run clicks fire before test discovery done → ~90% LWC E2E failures on windows-latest; reruns pass |
| 8 | +- violates repo rule (`coding-playwright-tests.md`: never `waitForTimeout`) |
| 9 | +- Helper called by 3 tests (run-all, single-component, single-case); all `createLwc(page,'lwc1')` first → `lwc1` tree item is universal readiness signal |
| 10 | +- run-all test issues `Test: Run All Tests` right after helper w/ NO tree wait → main flake source |
| 11 | +- `expect` not yet imported in this spec; `testItem` helper (line 38) already matches `treeitem name /label/i` |
| 12 | +- Precedent: `lwcDebugTests.desktop.spec.ts` uses `expect(...).toPass` — but note that file's toPass callbacks throw explicitly / check state then throw (lines 46-52); do NOT nest a bare `expect(...).toBeVisible()` inside a toPass callback (throws on first miss, kills retry loop) |
| 13 | + |
| 14 | +## Phases |
| 15 | + |
| 16 | +### Phase 1 — state wait in openAndRefreshTestExplorer |
| 17 | + |
| 18 | +- add `expect` to `@playwright/test` import |
| 19 | +- drop both `waitForTimeout`; after `Test: Refresh Tests`, wait on tree item via web-first assertion with built-in retry: |
| 20 | + `await expect(testItem(page, 'lwc1')).toBeVisible({ timeout: 30_000 });` |
| 21 | + (reuse `testItem` helper; tree populated = readiness. `toBeVisible` polls internally — no `toPass` wrapper needed) |
| 22 | +- DO NOT use the nested form `await expect(async () => { await expect(testItem(page,'lwc1')).toBeVisible(); }).toPass({ timeout })` — the inner `toBeVisible()` throws immediately when the element is not yet visible, so `toPass` never gets a chance to retry; the helper would fail on first miss instead of waiting for discovery |
| 23 | +- run-all test: tree exists before `Test: Run All Tests` |
| 24 | +- per-caller `lwc1.waitFor({state:'visible'})` redundant after helper but leave (out of scope; harmless) |
| 25 | + |
| 26 | +commit: `test(lwc): replace waitForTimeout with tree-item state wait in lwcRunTests Test Explorer helper - W-22972995` |
| 27 | + |
| 28 | +## Skills to apply |
| 29 | + |
| 30 | +- playwright-e2e (waiting patterns, toPass) |
| 31 | +- typescript (const arrow, no let) |
| 32 | +- thermonuclear-code-quality-review (pre-commit) |
| 33 | + |
| 34 | +## Verification |
| 35 | + |
| 36 | +- `npx eslint` on spec file — no lint errors (e.g. floating promise, import) |
| 37 | +- `npx tsc`/compile typecheck spec — clean |
| 38 | +- grep: no `waitForTimeout` in `openAndRefreshTestExplorer` |
| 39 | +- e2e-covered: `packages/salesforcedx-vscode-lwc/test/playwright/specs/lwcRunTests.desktop.spec.ts` runs on the `e2e-desktop-run-tests` job (matrix incl. windows-latest) defined in `.github/workflows/lwcPlaywrightE2E.yml:220-313` (spec invoked at lines 262/283; sequential `--last-failed` rerun at 290). Pass = first-attempt green on windows-latest with no rerun (verified by branch CI). |
0 commit comments