feat(e2e): autologin patch (dev) + 登录态路由测试脚本

- util_web devAutologin: localStorage[_test_token]=user|pass -> 登录API写Hive+dispatch currentUser
- 延迟3s执行等 Flutter/Hive ready (否则 httpPost hang)
- main.dart 调用 devAutologin
- run_auth.js: 注入token遍历登录态路由
- 已验证: autologin API 200 OK
This commit is contained in:
2026-08-03 01:50:12 +08:00
parent 901e42a41b
commit 33b54fe454
10 changed files with 221 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: true });
const ctx = await browser.newContext({ viewport: { width: 1280, height: 900 } });
// 注入 _test_tokenaddInitScript 在每个页面加载前执行)
await ctx.addInitScript(() => { localStorage['_test_token'] = '6477108200|8818'; });
const page = await ctx.newPage();
const logs = [];
page.on('console', m => logs.push(m.text()));
await page.goto('http://127.0.0.1:8099/', { waitUntil: 'load', timeout: 60000 });
await page.waitForTimeout(8000); // 等 autologin
const ok = logs.filter(l => l.includes('CK_AUTOLOGIN_OK'));
const fail = logs.filter(l => l.includes('CK_AUTOLOGIN_FAIL'));
console.log('autologin:', ok.length ? '✓ OK' : (fail.length ? '✗ FAIL '+fail[0].slice(0,100) : '? 未触发'));
// 访问 /me登录态
await page.goto('http://127.0.0.1:8099/me', { waitUntil: 'load' }).catch(()=>{});
await page.waitForTimeout(6000);
const errs = logs.filter(l => l.startsWith('CK_ERROR') || l.includes('PAGEERROR'));
console.log('/me 错误数:', errs.length);
if (errs.length) console.log(' ', errs[0].slice(0,150));
await browser.close();
})();