Peach: Local-first video metadata scraper and media manager.
test(web): 保留反复超时处的输入焦点与弹层现场
longmeidao26e3ea7b8b58
diff --git a/frontend/e2e/harness.ts b/frontend/e2e/harness.tsindex 3682b23ed..9d4d50472 100644--- a/frontend/e2e/harness.ts+++ b/frontend/e2e/harness.ts@@ -63,6 +63,29 @@ export async function launch(): Promise<Browser> {});}+/** 失败时保留焦点、输入和弹层现场;成功路径不额外查询页面。 */+export async function withPageDiagnostics<T>(page: Page, where: string | (() => string), action: () => Promise<T>): Promise<T> {+ try {+ return await action();+ } catch (error) {+ const state = await page.evaluate(() => ({+ path: location.pathname + location.search,+ ready: document.readyState,+ focus: document.activeElement?.outerHTML.slice(0, 600),+ query: document.querySelector<HTMLInputElement>('#q')?.value,+ layers: [...document.querySelectorAll('dialog,[role="dialog"],#searchMenu')].slice(0, 12).map(node => ({+ tag: node.tagName, id: node.id, hidden: (node as HTMLElement).hidden,+ expanded: node.getAttribute('aria-expanded'), text: node.textContent?.slice(0, 600),+ })),+ busy: [...document.querySelectorAll('[aria-busy="true"],[data-skeleton]')]+ .slice(0, 12).map(node => ({ tag: node.tagName, id: node.id, label: node.getAttribute('aria-label') })),+ })).catch(() => '未取得');+ const tree = await page.locator('body').ariaSnapshot({ timeout: 2000 }).catch(() => '未取得');+ throw new Error(`${typeof where === 'function' ? where() : where}:${String(error)}\n页面现场:${JSON.stringify(state)}\n无障碍树:\n${tree.slice(0, 4000)}`,+ { cause: error });+ }+}+/** 等待态以 `aria-busy="true"` 与 `data-skeleton` 为准;超时就是等待态卡住了。* 两个标记由页面自己写:island、遗留模板和 React 子树都得发出,这里才等得到。*diff --git a/frontend/e2e/jav-detail.test.ts b/frontend/e2e/jav-detail.test.tsindex 244253360..c60282822 100644--- a/frontend/e2e/jav-detail.test.ts+++ b/frontend/e2e/jav-detail.test.ts@@ -1,7 +1,7 @@import assert from 'node:assert/strict';import { after, before, describe, it } from 'node:test';import type { Browser } from 'playwright-core';-import { launch, layout, requiredEnv, settle, VIEWPORTS } from './harness.ts';+import { launch, layout, requiredEnv, settle, VIEWPORTS, withPageDiagnostics } from './harness.ts';import { JAV_DETAIL, mockJavDetail } from './jav-detail-fixture.ts';describe('库外 JAV 作品详情', () => {@@ -89,7 +89,9 @@ describe('库外 JAV 作品详情', () => {await panel.waitFor({ state: 'detached' });await page.keyboard.press('Escape');await page.locator('[data-modal-surface]').waitFor({ state: 'detached' });- assert.equal(await page.locator('#stage[open]').count(), 1, 'Escape 只关掉里层弹层');+ await withPageDiagnostics(page, 'Escape 只关掉里层弹层', async () => {+ assert.equal(await page.locator('#stage[open]').count(), 1, 'Escape 只关掉里层弹层');+ });await page.locator('[data-jav-actions]').getByRole('button', { name: '想要', exact: true }).click();await page.locator('#toasts [data-sonner-toast]').filter({ hasText: '已加入想要' }).waitFor();assert.deepEqual(await hit('#toasts [data-sonner-toast]'), { onTop: true, inStage: true }, '操作回执被详情浮窗盖住');diff --git a/frontend/e2e/search.test.ts b/frontend/e2e/search.test.tsindex 974761236..0a5f83bfe 100644--- a/frontend/e2e/search.test.ts+++ b/frontend/e2e/search.test.ts@@ -7,7 +7,7 @@ import { after, before, describe, it } from 'node:test';import type { Browser, Page } from 'playwright-core';-import { launch, unmanagedScrollers, VIEWPORTS } from './harness.ts';+import { launch, unmanagedScrollers, VIEWPORTS, withPageDiagnostics } from './harness.ts';import { openItemPage, type ItemVisit } from './item-fixture.ts';const DESKTOP = VIEWPORTS.find((viewport) => !viewport.mobile)!;@@ -75,13 +75,32 @@ async function typeQuery(opened: Search, text = SUGGEST.q) {const { page } = opened;await page.locator('#q').click();await page.keyboard.type(text);- await page.locator(`${OPTION}[data-search-value="七海の夏"]`).waitFor({ timeout: 5_000 });+ await withPageDiagnostics(page, () => `搜索建议(请求 ${opened.suggest.map(url => url.search).join('、')})`,+ () => page.locator(`${OPTION}[data-search-value="七海の夏"]`).waitFor({ timeout: 5_000 }));}describe('顶栏搜索', () => {let browser: Browser;before(async () => { browser = await launch(); });after(async () => { await browser?.close(); });+ it('等待失败保留原异常以及输入、焦点和菜单现场,成功时返回原结果', async () => {+ const context = await browser.newContext();+ try {+ const page = await context.newPage();+ await page.setContent('<input id="q" value="取证词"><div id="searchMenu">测试建议</div>');+ await page.locator('#q').focus();+ const failure = new Error('原始等待失败');+ await assert.rejects(withPageDiagnostics(page, '诊断夹具', async () => { throw failure }), error => {+ assert.equal((error as Error).cause, failure);+ assert.match((error as Error).message, /原始等待失败/);+ assert.match((error as Error).message, /取证词/);+ assert.match((error as Error).message, /测试建议/);+ assert.match((error as Error).message, /focus/);+ return true;+ });+ assert.equal(await withPageDiagnostics(page, '成功夹具', async () => 42), 42);+ } finally { await context.close(); }+ });for (const viewport of VIEWPORTS) {it(`${viewport.name} 搜索长列表使用覆盖式滑块并可拖动,关闭重开保留一套轨道`, async () => {diff --git a/frontend/e2e/table-preferences-fixture.ts b/frontend/e2e/table-preferences-fixture.tsindex b45fe1dbe..4f75bb73a 100644--- a/frontend/e2e/table-preferences-fixture.ts+++ b/frontend/e2e/table-preferences-fixture.ts@@ -1,6 +1,6 @@import assert from 'node:assert/strict';import type { Locator, Page } from 'playwright-core';-import { settle } from './harness.ts';+import { settle, withPageDiagnostics } from './harness.ts';/** 标题与整组操作共享一行或分行,同组列设置按钮保持在一起。 */async function verifyToolbarWrapping(page: Page) {@@ -61,7 +61,8 @@ export async function verifyTablePreferences(page: Page, table: Locator, label:const initial = await width();const handle = header.getByRole('slider');await handle.focus(); await handle.press('Enter');- await header.locator('.react-aria-ColumnResizer[data-resizing]').waitFor();+ await withPageDiagnostics(page, `${label}进入键盘列宽调整`,+ () => header.locator('.react-aria-ColumnResizer[data-resizing]').waitFor());await handle.press('ArrowRight'); await handle.press('ArrowRight');await page.waitForFunction(({ node, initial }) => node && node.getBoundingClientRect().width > initial,{ node: await header.elementHandle(), initial }, { timeout: 5000 });