Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

test(e2e): 转发路由在请求被取消时不再抛出未处理的拒绝

longmeidaoa3c9eb6cc3ec
diff --git a/frontend/e2e/http-configuration.test.ts b/frontend/e2e/http-configuration.test.ts
index 639f66b79..53e5edda2 100644
--- a/frontend/e2e/http-configuration.test.ts
+++ b/frontend/e2e/http-configuration.test.ts
@@ -14,12 +14,17 @@ describe('普通 HTTP 的配置与播放', () => {
const origin = 'http://peach-http.test';
const opened = await visit(browser, '/', viewport, async page => {
// 只将临时演示服务映射到普通 HTTP 来源;浏览器自行决定 Web Crypto 的可用性。
+ // 跳转与关页会取消还在转发的请求(播放器的拉流尤其如此),那一趟落空不算失败;其余错误照常抛出。
await page.route(`${origin}/**`, async route => {
const request = route.request();
const url = new URL(request.url());
- const response = await route.fetch({ url: service + url.pathname + url.search, maxRedirects: 0,
- headers: { ...request.headers(), host: new URL(service).host, origin: service } });
- await route.fulfill({ response });
+ try {
+ const response = await route.fetch({ url: service + url.pathname + url.search, maxRedirects: 0,
+ headers: { ...request.headers(), host: new URL(service).host, origin: service } });
+ await route.fulfill({ response });
+ } catch (error) {
+ if (!/already handled|disposed|closed/i.test(String(error))) throw error;
+ }
});
});
const { page, problems } = opened;
@@ -70,8 +75,7 @@ describe('普通 HTTP 的配置与播放', () => {
await page.locator('#stage .video-js video.vjs-tech').waitFor();
assert.deepEqual(problems, []);
} finally {
- await page.goto('about:blank');
- await page.unrouteAll({ behavior: 'wait' });
+ await page.unrouteAll({ behavior: 'ignoreErrors' });
await opened.close();
}
});
diff --git a/frontend/e2e/playback-resume.test.ts b/frontend/e2e/playback-resume.test.ts
index cf4217717..d78ee675f 100644
--- a/frontend/e2e/playback-resume.test.ts
+++ b/frontend/e2e/playback-resume.test.ts
@@ -36,8 +36,14 @@ describe('视频退出续播', () => {
: await openFollowFeed(browser, path, viewport, { ready: '#stage [data-follow-detail-side]' });
try {
const page = opened.page;
+ // 用例里的刷新与跳转会取消还在转发的片源请求,那一趟落空不算失败;其余错误照常抛出。
+ const settled = (error: unknown) => {
+ if (!/already handled|disposed|closed/i.test(String(error))) throw error;
+ };
await page.route((url) => ['/stream', '/follow-stream'].includes(url.pathname),
- async (route) => { await route.fulfill({ response: await route.fetch({ url: clip }) }) });
+ async (route) => {
+ try { await route.fulfill({ response: await route.fetch({ url: clip }) }) } catch (error) { settled(error) }
+ });
await page.route((url) => ['/api/activity', '/api/follow/activity', '/api/follow/play'].includes(url.pathname),
(route) => route.fulfill({ json: { ok: true } }));
const key = kind === 'item' ? `item:${ITEM.plain}` : `follow:${DETAIL.collection}:main`;
@@ -70,7 +76,7 @@ describe('视频退出续播', () => {
assert.deepEqual(opened.problems.filter((line) => !line.includes('VIDEOJS')), []);
} finally {
if (await opened.page.locator('#stage[open]').count()) await opened.page.locator('#closeStage').click();
- await opened.page.unrouteAll({ behavior: 'wait' });
+ await opened.page.unrouteAll({ behavior: 'ignoreErrors' });
await opened.close();
}
});