cloud-drive-renamer/tests/unit/manifest-platform-matches.test.ts
Zain 9ca7a6dfc8 feat(wkbrowser): 新增悟空网盘支持并更新相关文档配置
新增悟空网盘适配器,包含文件列表获取、重命名及 DOM 同步功能,更新国际化文案、商店描述、权限声明与测试用例
2026-08-15 20:01:55 +08:00

92 行
4.6 KiB
TypeScript

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/*');
});
it('injects Xunlei UI on pan.xunlei.com and allows its API host', () => {
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://pan.xunlei.com/*');
expect(manifest.host_permissions).toContain('https://api-pan.xunlei.com/*');
expect(contentScriptMatches).toContain('https://pan.xunlei.com/*');
expect(webAccessibleMatches).toContain('https://pan.xunlei.com/*');
});
it('injects Woozooo UI on pc.woozooo.com and allows its same-origin API', () => {
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://pc.woozooo.com/*');
expect(contentScriptMatches).toContain('https://pc.woozooo.com/*');
expect(webAccessibleMatches).toContain('https://pc.woozooo.com/*');
});
it('injects CMCC UI on yun.139.com and allows its API host', () => {
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.139.com/*');
expect(manifest.host_permissions).toContain('https://personal-kd-njs.yun.139.com/*');
expect(contentScriptMatches).toContain('https://yun.139.com/*');
expect(webAccessibleMatches).toContain('https://yun.139.com/*');
});
it('injects GuangyaPan UI on www.guangyapan.com and allows its API host', () => {
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://www.guangyapan.com/*');
expect(manifest.host_permissions).toContain('https://api.guangyapan.com/*');
expect(contentScriptMatches).toContain('https://www.guangyapan.com/*');
expect(webAccessibleMatches).toContain('https://www.guangyapan.com/*');
});
it('injects WKBrowser UI on pan.wkbrowser.com and allows its API host', () => {
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://pan.wkbrowser.com/*');
expect(manifest.host_permissions).toContain('https://api.wkbrowser.com/*');
expect(contentScriptMatches).toContain('https://pan.wkbrowser.com/*');
expect(contentScriptMatches).not.toContain('https://api.wkbrowser.com/*');
expect(webAccessibleMatches).toContain('https://pan.wkbrowser.com/*');
});
});