From 630d10fb547babe206a4bd5dfd8f5de85f89b588 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Tue, 6 Oct 2026 01:19:38 +0800 Subject: [PATCH] =?UTF-8?q?test(editor-host):=20=E7=AD=89=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=A0=91=E7=9C=9F=E7=9A=84=E6=B8=B2=E6=9F=93=E5=87=BA?= =?UTF-8?q?=E8=AF=A5=E8=A1=8C=E5=86=8D=E6=96=AD=E8=A8=80=EF=BC=88=E4=BF=AE?= =?UTF-8?q?=E6=85=A2=20runner=20=E4=B8=8A=E7=9A=84=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=AB=9E=E6=80=81=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 两个 mount helper 只 drain 微任务,而文件树层级缓存由异步 fs.trees 应答填充:一旦那次刷新 被排成宏任务,helper 返回时树仍在 loading 行,断言就找不到 [class*="explorerName"](CI 上 names= 为空 / 本地注入延迟时 names=tmp,CI 只报了第一个挂掉的用例,同一模式实际影响 3 个)。 改为 vi.waitFor 等待真实渲染条件(不是调大固定超时):树真列不出该行时仍按 1s 超时失败—— 反判别性检查(把 mock 里的 a.ts 换成永不出现的 b.ts)确认 3 个用例仍会在 1.0s 内失败。 300ms 宏任务注入下:修复前 5/5 轮全红(各 3 用例)→ 修复后 5/5 轮全绿 14/14。 纯测试改动,产品代码零改动(与 #855 无关:把 EditorHost.tsx 单独 revert 到 #855 之前, 同一探针仍 3/3 轮全红、文本逐字相同)。 --- tests/editor-host.spec.tsx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/editor-host.spec.tsx b/tests/editor-host.spec.tsx index 50a4ed98..d8302d38 100644 --- a/tests/editor-host.spec.tsx +++ b/tests/editor-host.spec.tsx @@ -53,6 +53,28 @@ vi.mock('../src/client/api.ts', () => ({ import { setupReactAct } from './test-utils.ts' setupReactAct() +/** + * Wait until the tree has rendered the row for `name` — the precondition of + * every tree interaction below. + * + * The level cache is filled by an async `fs.trees` answer, so the mount + * helpers' microtask drains only hand back an interactive tree when that + * answer happens to land inside them. On a loaded runner the scheduler can + * defer React's flush past those microtasks, and the tree is then still + * showing its loading row: the CI failure read `names=` (nothing rendered) + * or `names=tmp` (the root row only). Wait for the rendered CONDITION, never + * for a bigger fixed slice of time — a tree that never lists `name` is a real + * product failure and still fails the case, on the default `vi.waitFor` + * timeout. + */ +async function waitForTreeRow(container: HTMLElement, name: string): Promise { + await vi.waitFor(() => { + const found = [...container.querySelectorAll('[class*="explorerName"]')] + .some(el => el.textContent === name) + expect(found).toBe(true) + }) +} + /** A store with the seeded editor-home tab (default prefs: separate mode; * merged-mode scenarios re-enable editorExplorer explicitly). */ function setup(): { @@ -606,6 +628,7 @@ describe('EditorHost native-tab context-menu actions', () => { const { container, unmount } = await mountNative(ctx, store, service) try { const before = tabCount(store) + await waitForTreeRow(container, 'a.ts') clickOpenToSide(container) // 1) EditorHost routed the gesture to the service with the side target… expect(opens).toContainEqual({ type: 'editor', path: '/tmp/a.ts', target: 'side' }) @@ -641,6 +664,7 @@ describe('EditorHost native-tab context-menu actions', () => { const { container, unmount } = await mountHostWithTreeWithCwd(treeCtx as unknown as Context, store, fileTab) try { const before = tabCount(store) + await waitForTreeRow(container, 'a.ts') clickOpenToSide(container) // A bottom-workbench tab keeps the plugin's own split: a NEW tab in the // same pane family, and no side open was requested. @@ -662,6 +686,7 @@ describe('EditorHost native-tab context-menu actions', () => { const logged = vi.spyOn(console, 'error').mockImplementation(() => {}) const { container, unmount } = await mountNative(ctx, store, service) try { + await waitForTreeRow(container, 'a.ts') const row = [...container.querySelectorAll('[role="button"]')] .find(el => el.querySelector('[class*="explorerName"]')?.textContent === 'a.ts') expect(row).toBeDefined()