- 修复 web-admin 与 desktop-client 侧边栏点击无反应:el-menu 的 index 是路径,不能当路由名使用 - 修复 Web 产物目录含点号目录(如 .cache)时 res.sendFile 因 dotfiles:ignore 返回 500 - 后端生产模式:静态托管 Web 端 + SPA 回退、helmet、限流(通用/登录)、trust proxy、 /healthz 与 /readyz、请求耗时日志、生产环境变量强校验、首启动自动迁移与创建管理员、PID 文件 - Web 管理端 PWA:manifest + service worker + 图标,可在浏览器安装为应用 - 新增服务端 + Web 管理端 Windows 安装程序(内置 Node 运行时、启停与服务脚本、开机自启、卸载保留数据) - 新增 Docker/Compose/Nginx 部署样例与 docs/production.md - 新增 UI 回归测试:Web 端 Electron 驱动真实点击 7 项、客户端冒烟 11 项(含侧边栏点击与离线回退)
57 lines
2.1 KiB
JavaScript
57 lines
2.1 KiB
JavaScript
/**
|
|
* Electron 冒烟验证:以 ELECTRON_SMOKE_TEST=1 启动应用(不弹窗),
|
|
* 主进程会依次校验 preload 桥接、渲染进程挂载、登录页 DOM、
|
|
* IPC 往返、IndexedDB 缓存读写、断网回退缓存,然后自动退出。
|
|
*
|
|
* 前置条件:已执行 npm run build(需要 dist/main 与 dist/renderer)。
|
|
*/
|
|
import { spawn } from 'node:child_process';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import electronPath from 'electron';
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const required = [path.join(root, 'dist/main/index.js'), path.join(root, 'dist/renderer/index.html')];
|
|
const missing = required.filter((file) => !fs.existsSync(file));
|
|
|
|
if (missing.length > 0) {
|
|
console.error('[smoke] 缺少构建产物,请先执行构建:');
|
|
console.error(' pnpm --filter @classhelper/desktop-client build');
|
|
for (const file of missing) console.error(` 缺失: ${path.relative(root, file)}`);
|
|
process.exit(2);
|
|
}
|
|
|
|
console.log('[smoke] 启动 Electron 冒烟验证...\n');
|
|
|
|
// 未显式指定时自动探测后端:可达则启用联网集成 + 侧边栏点击测试
|
|
let online = process.env.ELECTRON_SMOKE_ONLINE;
|
|
if (online === undefined) {
|
|
online = '0';
|
|
try {
|
|
const controller = new AbortController();
|
|
const timer = setTimeout(() => controller.abort(), 2500);
|
|
const response = await fetch('http://127.0.0.1:4000/api/health', { signal: controller.signal });
|
|
clearTimeout(timer);
|
|
online = response.ok ? '1' : '0';
|
|
} catch {
|
|
online = '0';
|
|
}
|
|
console.log(
|
|
online === '1'
|
|
? '[smoke] 检测到后端在线,将执行联网集成与侧边栏点击测试'
|
|
: '[smoke] 后端未在线,仅执行本地检查(离线缓存/界面渲染);如需联网测试请先启动 pnpm dev:server',
|
|
);
|
|
}
|
|
|
|
const child = spawn(electronPath, ['.'], {
|
|
cwd: root,
|
|
stdio: 'inherit',
|
|
env: { ...process.env, ELECTRON_SMOKE_TEST: '1', ELECTRON_SMOKE_ONLINE: online },
|
|
});
|
|
|
|
child.on('exit', (code) => {
|
|
console.log(`\n[smoke] Electron 退出,code=${code ?? 1}`);
|
|
process.exit(code ?? 1);
|
|
});
|