test(editor-host): 条件等待前先给一个宏任务边界,预算抬到 10s
`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 绿。
This commit is contained in:
1 parent
45285014d9
commit
e656d5ba11
1 file changed
+12
-2
@@ -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<void> {
|
||||
// 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)
|
||||
|
||||
Reference in new issue
Block a user