From cb32e8aa5595faf9717e4a253fc935d9f034a1a9 Mon Sep 17 00:00:00 2001 From: Zain Date: Mon, 10 Aug 2026 11:37:08 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B7=BB=E5=8A=A0=E6=B8=85=E5=8D=95?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=B9=B3=E5=8F=B0=E5=8C=B9=E9=85=8D=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/unit/manifest-platform-matches.test.ts | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/unit/manifest-platform-matches.test.ts diff --git a/tests/unit/manifest-platform-matches.test.ts b/tests/unit/manifest-platform-matches.test.ts new file mode 100644 index 0000000..c2d0672 --- /dev/null +++ b/tests/unit/manifest-platform-matches.test.ts @@ -0,0 +1,36 @@ +import { describe, expect, it } from 'vitest'; +import { readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; + +interface ManifestContentScript { + matches?: string[]; +} + +interface ManifestWebAccessibleResource { + matches?: string[]; +} + +interface ExtensionManifest { + host_permissions?: string[]; + content_scripts?: ManifestContentScript[]; + web_accessible_resources?: ManifestWebAccessibleResource[]; +} + +function loadManifest(): ExtensionManifest { + return JSON.parse(readFileSync(resolve(process.cwd(), 'manifest.json'), 'utf-8')) as ExtensionManifest; +} + +describe('manifest platform matches', () => { + it('injects 123Pan UI only on yun.123pan.cn', () => { + const manifest = loadManifest(); + const contentScriptMatches = manifest.content_scripts?.flatMap((script) => script.matches ?? []) ?? []; + const webAccessibleMatches = manifest.web_accessible_resources?.flatMap((resource) => resource.matches ?? []) ?? []; + + expect(manifest.host_permissions).toContain('https://yun.123pan.cn/*'); + expect(manifest.host_permissions).not.toContain('https://www.123pan.com/*'); + expect(contentScriptMatches).toContain('https://yun.123pan.cn/*'); + expect(contentScriptMatches).not.toContain('https://www.123pan.com/*'); + expect(webAccessibleMatches).toContain('https://yun.123pan.cn/*'); + expect(webAccessibleMatches).not.toContain('https://www.123pan.com/*'); + }); +});