From 39e64378e446b5bd7c9ec1caf01b2cd8263b0607 Mon Sep 17 00:00:00 2001 From: cyfung1031 <44498510+cyfung1031@users.noreply.github.com> Date: Sat, 19 Sep 2026 07:10:09 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20=E5=8A=A0=E9=80=9F=20GM=5F?= =?UTF-8?q?xhr=20E2E=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/gm-api.spec.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/e2e/gm-api.spec.ts b/e2e/gm-api.spec.ts index 2a8194060..e79841391 100644 --- a/e2e/gm-api.spec.ts +++ b/e2e/gm-api.spec.ts @@ -451,6 +451,11 @@ async function startGMApiMockServer(): Promise { return; } + if (url.pathname === "/hang") { + // 超时和中止只要求请求保持未完成,不需要等待真实服务端的秒级延迟。 + return; + } + const delayMatch = url.pathname.match(/^\/delay\/(\d+)$/); if (delayMatch) { const delayMs = Number(delayMatch[1]) * 1000; @@ -545,6 +550,12 @@ function patchGMApiTestCode(code: string, mockOrigin: string): string { // @connect 127.0.0.1,而重复的 @connect 值会让脚本完全不执行。 .replace(/https:\/\/raw\.githubusercontent\.com\/\S*?\/([\w.-]+)\?/g, `${mockOrigin}/raw/$1?`) .replace(/https:\/\/translate\.googleapis\.com/g, mockOrigin) + // 慢端点只验证超时/中止和 progress 的相对顺序;在本地 mock 中压缩等待,避免 E2E 为真实秒级延迟买单。 + .replace(/\$\{HB\}\/delay\/(?:3|5|10)/g, "${HB}/hang") + .replace("timeout: 1000,", "timeout: 250,") + .replace("timeout: 2000,", "timeout: 250,") + .replace("{ abortAfterMs: 4000 }", "{ abortAfterMs: 300 }") + .replace(/duration=2&delay=1&numbytes=2048/g, "duration=0.5&delay=0.05&numbytes=2048") ); }