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/*'); + }); +});