cloud-drive-renamer/tests/unit/manifest-platform-matches.test.ts
Zain cefc989c20 refactor(cmcc): 改进API调用响应解析与平台检测
- 添加 `normalizeResponse` 方法处理嵌套 JSON 字符串响应
- 统一成功状态码验证逻辑
- 使用 XHR 传输保留请求头大小写
- 修复 SPA 根路径 `/w/` 的平台检测
- 添加 DOM 同步观察器断开逻辑
2026-08-15 08:34:57 +08:00

48 行
2.0 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 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/*');
});
});