Skip to content

Commit a6bad63

Browse files
committed
♻️ 回退 gm_download_test / gm_menu_test 至迁移前
8/8 审查指出的两个行为回归仍未修复: - gm_download 人工用例经 itManual 注册但从不执行动作(fn:null), 面板可点通过/失败造成假阳性; - gm_menu 丢失了 waitActions 的时间屏障,后续用例会改写待检查的菜单状态。 按 PR 讨论的回退方案,恢复这两个脚本迁移前的自包含实现: - 恢复 example/tests/gm_download_test.js / gm_menu_test.js(无 @require、自带 运行器与人工确认流程); - 移除 e2e/gm-api.spec.ts 中依赖 sctest 面板/统一输出的 GM_download E2E 用例 及其 @match 重写条目;共享的 sctest 本地重写与 mock server 保留(gm_xhr / gm_xhr_redirect 等仍在使用)。
1 parent 18f6eaa commit a6bad63

3 files changed

Lines changed: 580 additions & 309 deletions

File tree

e2e/gm-api.spec.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ function patchTargetMatchCode(code: string, targetUrl: string): string {
453453
const url = new URL(targetUrl);
454454
const targetPattern = `${url.protocol}//${url.hostname}/*${url.search}`;
455455
return code.replace(
456-
/^\/\/\s*@match\s+.*\?(gm_api_sync|gm_api_async|inject_content|early_inject_content|early_inject_page|WINDOW_MESSAGE_TEST_SC|SANDBOX_TEST_SC|unwrap_e2e_test|GM_XHR_REDIRECT_TEST_SC|GM_DOWNLOAD_TEST_SC|GM_XHR_TEST_SC)$/gm,
456+
/^\/\/\s*@match\s+.*\?(gm_api_sync|gm_api_async|inject_content|early_inject_content|early_inject_page|WINDOW_MESSAGE_TEST_SC|SANDBOX_TEST_SC|unwrap_e2e_test|GM_XHR_REDIRECT_TEST_SC|GM_XHR_TEST_SC)$/gm,
457457
`// @match ${targetPattern}`
458458
);
459459
}
@@ -479,7 +479,7 @@ function patchGMApiTestCode(code: string, mockOrigin: string): string {
479479
.replace(/https:\/\/www\.tampermonkey\.net\/favicon\.ico/g, `${mockOrigin}/favicon.ico`)
480480
.replace(/api\.github\.com\/repos\/scriptscat\/scriptcat/g, `${mockHost}/repos/scriptscat/scriptcat`)
481481
.replace(/httpbingo\.org\/get/g, `${mockHost}/get`)
482-
// gm_xhr_redirect_test.js / gm_download_test.js / gm_xhr_test.js build every request URL off
482+
// gm_xhr_redirect_test.js / gm_xhr_test.js build every request URL off
483483
// this constant rather than writing literal https://httpbingo.org/... URLs.
484484
.replace(/const HB = "https:\/\/httpbingo\.org";/, `const HB = "${mockOrigin}";`)
485485
// gm_xhr_test.js 拉三个固定的 raw.githubusercontent.com 文件,按文件名映射到本地 /raw/<file>。
@@ -860,29 +860,6 @@ test.describe("GM API", () => {
860860
expect(passed, "No test results found - script may not have run").toBeGreaterThan(0);
861861
});
862862

863-
test("GM_download tests (gm_download_test.js)", async ({ context, extensionId }) => {
864-
const { passed, failed, logs } = await runTestScript(
865-
context,
866-
extensionId,
867-
"gm_download_test.js",
868-
`${gmApiMockServer.origin}/?GM_DOWNLOAD_TEST_SC`,
869-
120_000,
870-
{
871-
patchCode,
872-
requireOrigin: gmApiMockServer.origin,
873-
// 两个 suite 都是 auto:false;统一入口会执行自动用例,itManual 仍保持待人工确认。
874-
beforeCollect: clickSuiteRunButton("GM_download 自动套件"),
875-
}
876-
);
877-
878-
console.log(`[gm_download_test] passed=${passed}, failed=${failed}`);
879-
if (failed !== 0) {
880-
console.log("[gm_download_test] logs:", logs.join("\n"));
881-
}
882-
expect(failed, "Some GM_download tests failed").toBe(0);
883-
expect(passed, "No test results found - script may not have run").toBeGreaterThan(0);
884-
});
885-
886863
test("GM_xhr tests (gm_xhr_test.js)", async ({ context, extensionId }) => {
887864
const { passed, failed, logs } = await runTestScript(
888865
context,

0 commit comments

Comments
 (0)