镜像自地址
https://github.com/lhly/cloud-drive-renamer.git
已同步 2026-10-20 05:37:47 +08:00
添加了包括单元测试、集成测试和性能测试在内的全面测试套件,覆盖核心功能如批量重命名、崩溃恢复、冲突检测等。测试文件包括: 1. 单元测试:helpers、rules、storage、retry等核心模块 2. 集成测试:批量执行流程与网络恢复场景 3. 性能测试:100文件处理时间、内存占用等指标 4. E2E测试:扩展加载、批量重命名完整流程 所有测试遵循vitest和playwright规范,确保功能稳定性和性能达标
60 行
1.7 KiB
TypeScript
60 行
1.7 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
/**
|
|
* E2E测试: 扩展加载和基本功能
|
|
*
|
|
* 测试扩展是否能正确加载到浏览器中,并验证基本功能可用性
|
|
*/
|
|
|
|
test.describe('扩展加载测试', () => {
|
|
test('应该成功加载扩展', async ({ page }) => {
|
|
// 导航到夸克网盘测试页面
|
|
await page.goto('https://pan.quark.cn');
|
|
|
|
// 等待页面加载
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// 验证页面标题
|
|
await expect(page).toHaveTitle(/夸克网盘/);
|
|
});
|
|
|
|
test('应该在页面中注入内容脚本', async ({ page }) => {
|
|
await page.goto('https://pan.quark.cn');
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
// 等待一段时间让内容脚本注入
|
|
await page.waitForTimeout(2000);
|
|
|
|
// 验证自定义元素是否已注册
|
|
const hasRenameButton = await page.evaluate(() => {
|
|
return customElements.get('rename-button') !== undefined;
|
|
});
|
|
|
|
expect(hasRenameButton).toBe(true);
|
|
});
|
|
|
|
test('应该能够访问扩展的background service worker', async ({ context }) => {
|
|
// 获取service worker
|
|
const serviceWorker = await context.serviceWorkers()[0];
|
|
expect(serviceWorker).toBeDefined();
|
|
});
|
|
|
|
test('应该能够打开扩展popup', async ({ page, context }) => {
|
|
// 获取扩展ID
|
|
const extensionId = await page.evaluate(() => {
|
|
return chrome?.runtime?.id;
|
|
});
|
|
|
|
if (extensionId) {
|
|
// 打开popup页面
|
|
const popupPage = await context.newPage();
|
|
await popupPage.goto(`chrome-extension://${extensionId}/popup.html`);
|
|
|
|
// 验证popup加载成功
|
|
await expect(popupPage.locator('h1')).toHaveText(/云盘批量重命名/);
|
|
|
|
await popupPage.close();
|
|
}
|
|
});
|
|
});
|