CloudLab CI/CD / 门禁 doctor (push) Failing after 2m4s
CloudLab CI/CD / 单元测试 (push) Skipped
CloudLab CI/CD / 归档完整性 (push) Skipped
CloudLab CI/CD / 构建站点与归档 (push) Skipped
CloudLab CI/CD / 部署到 lab.hdtime.space(rsync) (push) Skipped
CloudLab CI/CD / 构建镜像并推送 Gitea 容器仓库 (push) Skipped
CloudLab CI/CD / 容器部署到 lab.hdtime.space (push) Skipped
CloudLab CI/CD / 发布版本(Tag) (push) Skipped
- 引擎 createMatrix(n):N≤9 用预设,N>9 基于预设模板循环生成并编号(id 唯一) - 对比页加对照组数量设置:数字输入 + 预设 9/16/25/50,数量偏好本机保存 - 网格列数自适应:9→3 列、16→4、25→5、50→8(√N);预览矩阵同步 - load() 恢复不再硬编码 9;标题与批量操作文案通用化(去「九个」) - 验证:不变量 216/FAIL 0、数量设置 9/9、引擎回归 PASS Co-Authored-By: WorkBuddy <noreply@workbuddy.ai>
62 lines
3.9 KiB
JavaScript
62 lines
3.9 KiB
JavaScript
#!/usr/bin/env node
|
|
// 对照组数量设置验证:默认 9 → 预设 25 → 输入 50
|
|
import { spawn } from 'node:child_process';
|
|
import { createServer } from 'node:http';
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import { dirname, join, extname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
const ROOT = join(HERE, '..');
|
|
const OUT = join(ROOT, '..', '.workbuddy', 'shots');
|
|
const MIME = { '.html': 'text/html', '.css': 'text/css', '.js': 'text/javascript', '.svg': 'image/svg+xml', '.json': 'application/json' };
|
|
const srv = createServer((q, r) => { let p = decodeURIComponent(q.url.split('?')[0]); if (p.endsWith('/')) p += 'index.html'; let b; try { b = readFileSync(join(ROOT, p)); } catch { r.writeHead(404); r.end(); return; } r.writeHead(200, { 'Content-Type': MIME[extname(p)] || 'application/octet-stream' }); r.end(b); });
|
|
await new Promise(r => srv.listen(0, '127.0.0.1', r));
|
|
const BASE = `http://127.0.0.1:${srv.address().port}`;
|
|
const chrome = spawn('C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', ['--headless=new', '--disable-gpu', '--remote-debugging-port=9237', '--user-data-dir=' + join(OUT, '_pn'), 'about:blank']);
|
|
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
let targets;
|
|
for (let i = 0; i < 40; i++) { try { targets = await (await fetch('http://127.0.0.1:9237/json/list')).json(); if (targets.length) break; } catch {} await sleep(400); }
|
|
const ws = new WebSocket(targets.find(t => t.type === 'page').webSocketDebuggerUrl);
|
|
await new Promise(r => ws.onopen = r);
|
|
let id = 0; const pending = new Map();
|
|
ws.onmessage = e => { const m = JSON.parse(e.data); if (m.id && pending.has(m.id)) { pending.get(m.id)(m); pending.delete(m.id); } };
|
|
const send = (m, p = {}) => new Promise(res => { const i = ++id; pending.set(i, res); ws.send(JSON.stringify({ id: i, method: m, params: p })); });
|
|
const ev = async ex => { const r = await send('Runtime.evaluate', { expression: ex, returnByValue: true }); return r.result && r.result.result ? r.result.result.value : undefined; };
|
|
let pass = 0, fail = 0;
|
|
const check = (n, c) => { console.log((c ? ' ✅ ' : ' ❌ ') + n); c ? pass++ : fail++; };
|
|
const cellCount = () => ev(`document.querySelectorAll('#cmp-grid .cmp-cell').length`);
|
|
const gridCols = () => ev(`document.getElementById('cmp-grid').style.gridTemplateColumns`);
|
|
const label = () => ev(`document.getElementById('cmp-count-label').textContent`);
|
|
|
|
await send('Page.navigate', { url: BASE + '/app/compare.html' });
|
|
await sleep(2200);
|
|
|
|
check('默认 9 个对照组', (await cellCount()) === 9);
|
|
check('默认 3 列矩阵', (await gridCols()).indexOf('repeat(3,') === 0);
|
|
|
|
// 预设 25
|
|
await ev(`(function(){var b=document.querySelector('.cmp-count-presets button[data-n="25"]'); if(b) b.click(); return 1;})()`);
|
|
await sleep(700);
|
|
check('设为 25 个对照组', (await cellCount()) === 25);
|
|
check('25 个时 5 列矩阵', (await gridCols()).indexOf('repeat(5,') === 0);
|
|
check('数量标签同步为 25', (await label()) === '25');
|
|
|
|
// 截图 25 宫格
|
|
let r = await send('Page.captureScreenshot', { format: 'png' });
|
|
if (r.result && r.result.data) writeFileSync(join(OUT, 'cmp-25.png'), Buffer.from(r.result.data, 'base64'));
|
|
|
|
// 输入 50
|
|
await ev(`(function(){var i=document.getElementById('cmp-count'); i.value='50'; i.dispatchEvent(new Event('change',{bubbles:true})); return 1;})()`);
|
|
await sleep(700);
|
|
check('输入 50 个对照组', (await cellCount()) === 50);
|
|
check('50 个时 8 列矩阵', (await gridCols()).indexOf('repeat(8,') === 0);
|
|
check('数量标签同步为 50', (await label()) === '50');
|
|
|
|
// 刷新后偏好保留
|
|
await send('Page.navigate', { url: BASE + '/app/compare.html' });
|
|
await sleep(2000);
|
|
check('刷新后保留 50 个偏好', (await cellCount()) === 50);
|
|
|
|
console.log(`\n结果: ${pass} 通过 / ${fail} 失败`);
|
|
ws.close(); chrome.kill(); srv.close(); process.exit(fail ? 1 : 0);
|