47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
|
|
import { FullConfig } from '@playwright/test';
|
|||
|
|
import fs from 'fs';
|
|||
|
|
import path from 'path';
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Playwright E2E全局清理
|
|||
|
|
* 在测试结束后执行:
|
|||
|
|
* 1. 清理测试数据
|
|||
|
|
* 2. 关闭资源
|
|||
|
|
* 3. 生成测试报告
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
async function globalTeardown(config: FullConfig) {
|
|||
|
|
console.log('');
|
|||
|
|
console.log('🧹 开始E2E测试全局清理...');
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
// 1. 读取测试数据
|
|||
|
|
const testDataPath = path.join(__dirname, '..', '.e2e-test-data.json');
|
|||
|
|
|
|||
|
|
if (fs.existsSync(testDataPath)) {
|
|||
|
|
const testData = JSON.parse(fs.readFileSync(testDataPath, 'utf-8'));
|
|||
|
|
|
|||
|
|
// 2. 清理测试数据(可选:调用后端API删除测试数据)
|
|||
|
|
console.log(` 📋 清理测试活动 ID=${testData.activityId}`);
|
|||
|
|
|
|||
|
|
// 3. 删除测试数据文件
|
|||
|
|
fs.unlinkSync(testDataPath);
|
|||
|
|
console.log(' ✅ 测试数据文件已清理');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 4. 生成测试摘要
|
|||
|
|
console.log('');
|
|||
|
|
console.log('📊 E2E测试摘要');
|
|||
|
|
console.log(' 查看完整报告: npx playwright show-report e2e-report');
|
|||
|
|
console.log('');
|
|||
|
|
|
|||
|
|
console.log('✅ 全局清理完成!');
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('❌ 全局清理出错:', error);
|
|||
|
|
// 不抛出错误,避免影响测试报告
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export default globalTeardown;
|