From 62d9829a0c8f4e4aa7ebb7238a09214ca822ffe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=94=B7?= Date: Tue, 28 Apr 2026 10:52:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(e2e):=20=E6=9C=BA=E6=9E=84=E9=A1=B5?= =?UTF-8?q?=E5=B0=B1=E7=BB=AA=E5=88=A4=E6=96=AD=E6=94=B9=E4=B8=BA=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E8=BD=AE=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 避免 Promise.race 分支 waitFor 超时直接失败,改为 #app 文本与机构 cell 的组合条件轮询。 Made-with: Cursor --- tests/org-data-isolation.spec.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/org-data-isolation.spec.ts b/tests/org-data-isolation.spec.ts index a1971e1..14d6ee7 100644 --- a/tests/org-data-isolation.spec.ts +++ b/tests/org-data-isolation.spec.ts @@ -221,18 +221,22 @@ test.describe('多机构数据隔离(会话与 token)', () => { test.skip(true, '打开机构页时会话已退回访客态'); } - // 线上壳层不一定是 .main>h4(路由/构建差异);任一就绪即可 - await Promise.race([ - page.locator('#app').getByText(/请选择机构/).first().waitFor({ - state: 'visible', - timeout: 90_000, - }), - page.getByText('暂无可用机构').waitFor({ state: 'visible', timeout: 90_000 }), - page - .locator('#app .van-cell-group .van-cell') - .first() - .waitFor({ state: 'visible', timeout: 90_000 }), - ]); + // 线上壳层可能存在结构差异;轮询任一机构页就绪信号,避免分支超时互相误杀 + await expect + .poll( + async () => + page.evaluate(() => { + const appRoot = document.querySelector('#app'); + if (!appRoot) return false; + const rootText = appRoot.textContent ?? ''; + const hasOrgTitle = /请选择机构/.test(rootText); + const hasEmptyHint = rootText.includes('暂无可用机构'); + const hasOrgCells = !!appRoot.querySelector('.van-cell-group .van-cell'); + return hasOrgTitle || hasEmptyHint || hasOrgCells; + }), + { timeout: 90_000, intervals: [500, 1000, 2000] } + ) + .toBeTruthy(); if ( await page.getByText('暂无可用机构').isVisible().catch(() => false)