35 lines
1.6 KiB
TypeScript
35 lines
1.6 KiB
TypeScript
/**
|
|
* 必测执行前置:清空当前平台账号下**所有**设备,确保 connect 用例真正走添加流程。
|
|
* 删除方式:首页长按卡片 → 多选模式 → Delete → 确认(逐个,跨房间不能一起删)。删完清空注册表。
|
|
*
|
|
* 安全开关:必须 RESET_DEVICES=1 才执行(防误删)。按平台:PLATFORM=android/ios。
|
|
* RESET_DEVICES=1 PLATFORM=android npx ts-node scripts/reset-devices.ts
|
|
*/
|
|
import * as dotenv from 'dotenv';
|
|
import * as path from 'path';
|
|
dotenv.config({ path: path.resolve(__dirname, '../.env') });
|
|
import { createDriver } from '../drivers/factory';
|
|
import { removeAllDevices, homepageHasDeviceCards } from '../utils/common';
|
|
|
|
async function main() {
|
|
if (process.env.RESET_DEVICES !== '1') {
|
|
console.error('已阻止:这是删除所有设备的操作。确认后用 RESET_DEVICES=1 重跑。');
|
|
process.exit(2);
|
|
}
|
|
const driver = createDriver();
|
|
await driver.createSession();
|
|
try {
|
|
const removed = await removeAllDevices(driver);
|
|
console.log(`\n[reset] 平台=${process.env.PLATFORM || 'ios'} 删除 ${removed.length} 个设备:`, removed.join(', ') || '(无)');
|
|
// 删后校验:首页若仍有设备卡 → reset 没清干净(如批量删卡失败),exit 1 让上层(soak)记为"reset 异常",
|
|
// 避免后续 connect 走 SKIP 把通过率灌水。
|
|
if (await homepageHasDeviceCards(driver)) {
|
|
console.error('[reset] 警告:首页仍有设备卡,未清空干净!');
|
|
process.exitCode = 1;
|
|
}
|
|
} finally {
|
|
await driver.destroySession();
|
|
}
|
|
}
|
|
main().catch((e) => { console.error('ERR:', e.message); process.exit(1); });
|