From e656d5ba114d0e16eca5cf50f23d271d8a033307 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Thu, 8 Oct 2026 22:46:27 +0800 Subject: [PATCH] =?UTF-8?q?test(editor-host):=20=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E5=89=8D=E5=85=88=E7=BB=99=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=AE=8F=E4=BB=BB=E5=8A=A1=E8=BE=B9=E7=95=8C=EF=BC=8C=E9=A2=84?= =?UTF-8?q?=E7=AE=97=E6=8A=AC=E5=88=B0=2010s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `05d259cc` 把 `waitForTreeRow` 换成显式条件预算后,CI 上仍然红了一次,而且这次 **整整耗光了 5s**(5044ms,`vi.waitFor.timeout tests/editor-host.spec.tsx:89`), 下一轮同样的代码又是绿的 —— 说明问题不只是「预算太小」,而是那一轮里树的那次 flush 根本没被排上。 mount helper(`mountHostWithTreeWithCwd` 等)只 drain 两个微任务,而负载下 React 把异步 `fs.trees` 应答引发的 `setState` + flush 整个推迟到微任务之后是完全可能的 (`630d10f` 的提交信息已经记下这个机制)。所以现在在条件等待之前先让出一个**宏任务 边界**,给那次被推迟的 flush 一个真正运行的机会,再把预算放在 10s(仍在套件 `testTimeout: 15s` 之下,真正列不出该行时照样红在断言上,而不是红在测试时钟上)。 纯测试改动;本机 `tests/editor-host.spec.tsx` 14/14 绿。 --- tests/editor-host.spec.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/editor-host.spec.tsx b/tests/editor-host.spec.tsx index a5940fb3..9669c65f 100644 --- a/tests/editor-host.spec.tsx +++ b/tests/editor-host.spec.tsx @@ -65,9 +65,11 @@ setupReactAct() * * This is still a CONDITION wait, not the "bigger fixed slice of time" the * note below warns against: it returns the moment the row renders, and a tree - * that can never list it still fails the case — just after 5s instead of 1s. + * that can never list it still fails the case — just after 10s instead of 1s. + * 10s sits under the suite's 15s `testTimeout`, so a genuinely missing row + * still fails on the ASSERTION rather than on the test clock. */ -const RENDER_WAIT_MS = 5_000 +const RENDER_WAIT_MS = 10_000 /** * Wait until the tree has rendered the row for `name` — the precondition of @@ -83,6 +85,14 @@ const RENDER_WAIT_MS = 5_000 * product failure and still fails the case. */ async function waitForTreeRow(container: HTMLElement, name: string): Promise { + // Give the scheduler a MACROTASK boundary first: the mount helpers drain + // microtasks only, and under load React can defer the tree's level flush + // past them entirely (the 2026-10-08 failure spent the whole budget waiting + // for a flush that had not been scheduled yet — it failed at 5044ms with a + // 5s budget, and passed on the very next run). The condition wait below is + // unchanged; this just stops the budget from ticking before the deferred + // work has had any chance to run. + await act(async () => { await new Promise(resolve => { setTimeout(resolve, 0) }) }) await vi.waitFor(() => { const found = [...container.querySelectorAll('[class*="explorerName"]')] .some(el => el.textContent === name)