Skip to content

test: wait for web form session restore before asserting - #62

Merged
magicapple123 merged 1 commit into
mainfrom
test/webform-session-wait
Oct 2, 2026
Merged

magicapple123 merged 1 commit into
mainfrom
test/webform-session-wait

Conversation

@magicapple123

Copy link
Copy Markdown
Owner

背景

#58(react-router-dom 7.18.2 → 7.18.4)的唯一失败作业 Frontend (Node 20) 死在:

WebFormPage.test.tsx > restores the unfinished web form session when returning from another page
TestingLibraryElementError: Unable to find an accessible element with the role "button" and name /结束本次填写/

判定:测试自身的时序竞态(非 7.18.4 行为变化)

1. 渲染门控证据:「结束本次填写」的渲染条件是 running && (sessionActive || live?.running)(WebFormPage.tsx)。除 sessionStorage 会话恢复外,它还依赖 getWebFormBrowserStatus 轮询返回的 running —— 与「填充到页面」按钮不在同一次状态提交。原测试在 waitFor「填充到页面」出现后同步 getByRole 断言「结束本次填写」,CI 高负载下后者尚未提交即抛错。

2. router 变更证据:7.18.3(性能/校验)与 7.18.4(RSC redirect 转义 + #15485 避免在初始 hydration / router.revalidate() 时调用 document.startViewTransition)均无会话恢复相关行为变更;7.18.4 的 #15485 是纯粹的时序变化,恰好说明它只会移动竞态窗口,而非破坏功能。

3. 复现证据:7.18.4 下单用例文件 15 连跑全绿;7.18.4 全量套件(801 用例)本地全绿;失败仅在 CI 负载下偶发 —— 与 #60 的 useWatch 竞态同类。

修复

两处同步断言改为 findByRole / findByDisplayValue 等待落地(等正确值渲染后再断言,断言本身零放松),并注明原因。

验证

  • vitest:123 文件 / 801 用例全绿
  • eslint:0 error / 11 warning(基线)
  • tsc --noEmit、prettier --check:通过

WebFormPage「跨页返回恢复未完成会话」用例在 CI 上偶发失败
(#58 的 Frontend 作业):

    TestingLibraryElementError: Unable to find an accessible element
    with the role "button" and name /结束本次填写/

根因是测试自身的时序竞态,而非 router 7.18.4 的行为变化:

- 「结束本次填写」按钮的渲染门控是 `running && (sessionActive || live?.running)`
  (WebFormPage.tsx),除了 sessionStorage 的会话恢复外,还依赖
  getWebFormBrowserStatus 轮询返回的 running —— 它与「填充到页面」按钮
  不在同一次状态提交里。
- 原断言在 waitFor「填充到页面」出现后**同步** getByRole「结束本次填写」,
  高负载下后者尚未提交即抛错。
- 佐证:router 7.18.3/7.18.4 changelog 无会话恢复相关变更
  (7.18.4 仅 RSC redirect 转义与 #15485 避免 startViewTransition 的时序
  变化);本地 7.18.4 下单文件 15 连跑 + 全量套件均绿,失败只在 CI
  负载下偶发,与 #60 的 useWatch 竞态同类。

修复:两处同步断言改为 findByRole / findByDisplayValue 等待落地,
断言内容(role / name / 值)不变,无放松。

验证:vitest 801/801(123 文件);eslint 0 error / 11 warning(基线);
tsc --noEmit、prettier --check 通过。
@magicapple123
magicapple123 merged commit ce7d1b4 into main Oct 2, 2026
10 checks passed
@magicapple123
magicapple123 deleted the test/webform-session-wait branch October 2, 2026 12:30
magicapple123 pushed a commit that referenced this pull request Oct 2, 2026
Patch bump. This PR's Frontend check is red due to the WebFormPage session-restore race that #62 already fixed on main (the PR branch predates that fix; dependabot rebase did not land in time). The combined state (router 7.18.4 + test fix) was validated locally with 15 consecutive green full-suite runs before #62 merged; main CI on this merge is the authoritative gate.
magicapple123 added a commit that referenced this pull request Oct 3, 2026
React 19 + antd 6 下面板异步挂载在 CI Node 20 慢机上可能超过 waitFor 默认 1s,previewResumeTemplate 调用数断言放宽到 5s(等的就是正确值,断言本身不变)。与 #60/#62 同类的 CI 时序修正。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant