cloud-drive-renamer/tests/unit/manifest-platform-matches.test.ts
Zain d32e5ef66c feat(woozooo): 新增蓝奏云网盘支持
新增蓝奏云网盘适配,支持文件列表获取、重命名及域名注入;
更新相关文档、测试用例及多语言描述,将蓝奏云纳入支持平台。
2026-08-15 10:37:34 +08:00

69 行
3.2 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/*');
});
});