ci: verify:ci 增加 e2e 冒烟(31 条,约 45s)

背景:e2e 长期只有手动命令,UI 漂移无人拦(2026-11-27 实测积压过 128 条红)。
在门禁末尾加一步冒烟,兜住「应用起不来 / 画布打不开 / 数据不落盘」这类致命回归。

scripts/e2e-smoke.js:
- 动态分配空闲端口(固定端口会被残留测试服占用,实测假红)起 scripts/serve-test.js
- 跑 iwb-stability(26)+ iwb-canvas-ux(5),--workers=4,约 45s
- 无论成败都关掉测试服;失败输出测试服 stderr 与退出码
- 支持 --list 查看冒烟集

package.json:新增 test:e2e:smoke;verify:ci 末尾串上它。
CONTRIBUTING / docs/testing:补门禁清单与选型原则。

验证:npm run verify:ci 全绿(rc=0,冒烟 31 passed / 45.5s)。
This commit is contained in:
qiqi authored and qiqi@local committed 2026-11-27 07:46:38 +08:00
1 parent 03b34819f8
commit 52b7886599
4 files changed
+121 -4

No files matched your search

+5 -2
View File
@@ -29,8 +29,9 @@
## 3. 门禁:改完必须跑绿
```bash
npm run verify:ci # 完整 CI 门禁(build → check → lint → typecheck → unit → test → facts)
npm run test:e2e # Playwright 端到端(会自己 build)
npm run verify:ci # 完整 CI 门禁(build → check → lint → typecheck → unit → test → facts → e2e 冒烟)
npm run test:e2e # Playwright 端到端全量(会自己 build;环境依赖用例默认跳过,见 tests/_helpers/env.js)
npm run test:e2e:smoke # 只跑冒烟集(门禁里那 31 条)
```
`verify:ci` 展开为:
@@ -46,6 +47,8 @@ test:facts 事实基线守门(见 §5)
typecheck 渐进类型检查(tsc --noEmit;范围 = src/*.js,不含 app.js)
sync:facts 事实同步器(dry-run:列出文档/快照与实际不一致处)
sync:facts:write 写入可机械同步的事实(文档计数等),见 §5
test:e2e:smoke e2e 冒烟(2026-11-27 起):自动起测试服 → 跑 iwb-stability + iwb-canvas-ux(31 条,约 45s)
⇒ 兜住「应用起不来 / 画布打不开 / 数据不落盘」这类致命回归;全量 e2e 仍手动跑
```
**只跑单个测试**:
+9
View File
@@ -42,3 +42,12 @@ IWB_E2E_ENV_DEPS=1 npx playwright test tests/clipboard-audit.spec.js
- `tests/fixtures/e2e-known-red.json` 已清空(0 已知红);`node scripts/e2e-known-red-report.js` 之后出现任何红都是**新增回归**。
- 已退役 2 个 spec(`iwb-lib-panel-ux` / `iwb-full-window-resize`),原因见该文件 `retired` 段。
## 已进门禁(2026-11-27)
`verify:ci` 末尾新增 `npm run test:e2e:smoke`(`scripts/e2e-smoke.js`):
- 自动分配空闲端口起测试服 → 跑 `iwb-stability`(26 条)+ `iwb-canvas-ux`(5 条)→ 关闭测试服
- 约 45s;失败即门禁红
- 选型原则:只放「稳、快、覆盖核心路径」的 spec(启动/渲染/刷新保留/取景/缩放/框选/预览复制)
- 全量 e2e 仍是手动 `npx playwright test`;环境依赖用例默认跳过(`IWB_E2E_ENV_DEPS=1` 打开)
+3 -2
View File
@@ -25,7 +25,7 @@
"test:e2e": "npm run build && node scripts/serve-test.js",
"test:e2e:local": "node scripts/serve-test.js",
"e2e:known-red": "node scripts/e2e-known-red-report.js",
"verify:ci": "npm run build && node --check app.js && node --check dist/app.js && node scripts/check-dist.js && npm run tokens:check && npm run lint:tokens && npm run lint && npm run typecheck && npm run test:unit && npm test && npm run test:facts",
"verify:ci": "npm run build && node --check app.js && node --check dist/app.js && node scripts/check-dist.js && npm run tokens:check && npm run lint:tokens && npm run lint && npm run typecheck && npm run test:unit && npm test && npm run test:facts && npm run test:e2e:smoke",
"verify": "npm run verify:ci && npm run test:e2e",
"verify:release": "node scripts/verify-release.js",
"coverage:e2e": "node scripts/coverage-e2e.js",
@@ -34,7 +34,8 @@
"typecheck": "tsc -p tsconfig.json",
"release:desktop": "bash scripts/release.sh",
"lint:tokens": "node scripts/token-lint.js",
"test:tokens": "node tests/design-token-ratchet-test.js && node tests/theme-contrast-test.js"
"test:tokens": "node tests/design-token-ratchet-test.js && node tests/theme-contrast-test.js",
"test:e2e:smoke": "node scripts/e2e-smoke.js"
},
"devDependencies": {
"@playwright/test": "^1.64.1",
+104
View File
@@ -0,0 +1,104 @@
'use strict'
/* e2e 冒烟(2026-11-27 进 verify:ci)
*
* 为什么需要:e2e 一直只有手动命令,UI 漂移没人拦(2026-11-27 实测积压 128 条红)。
* 这里只跑「启动 + 画布交互 + 持久化」这一小撮最稳、最有代表性的 spec(~30s),
* 用来在门禁里兜住「应用根本起不来 / 画布打不开 / 数据不落盘」这类致命回归。
*
* 全量 e2e 仍走手动:npx playwright test(环境依赖用例默认跳过,见 tests/_helpers/env.js)。
*
* 用法:node scripts/e2e-smoke.js(可加 --list 只看要跑哪些 spec)
*/
const { spawn } = require('node:child_process')
const http = require('node:http')
const fs = require('node:fs')
const path = require('node:path')
const net = require('node:net')
const root = path.resolve(__dirname, '..')
// 端口动态分配:固定端口会被上一次残留的测试服占用(实测 EADDRINUSE 导致冒烟假红)
const freePort = () => new Promise((resolve, reject) => {
const s = net.createServer()
s.on('error', reject)
s.listen(0, '127.0.0.1', () => { const p = s.address().port; s.close(() => resolve(p)) })
})
// 冒烟集:只放「稳、快、覆盖核心路径」的 spec。新增请先单独跑 10 次确认不抖。
const SPECS = [
'tests/iwb-stability.spec.js', // 启动 / 渲染 / 刷新保留 / 多标签 / 图库面板开合
'tests/iwb-canvas-ux.spec.js', // 取景 / 缩放 / 框选多选 / 预览复制
]
if (process.argv.includes('--list')) {
console.log(SPECS.join('\n'))
process.exit(0)
}
if (!fs.existsSync(path.join(root, 'dist', 'index.html'))) {
console.error('[e2e-smoke] 缺少 dist/ —— 先跑 npm run build')
process.exit(1)
}
const wait = (ms) => new Promise((r) => setTimeout(r, ms))
function ping (base) {
return new Promise((resolve) => {
const req = http.get(base + '/', (res) => { res.resume(); resolve(res.statusCode === 200) })
req.on('error', () => resolve(false))
req.setTimeout(1000, () => { req.destroy(); resolve(false) })
})
}
async function main () {
const PORT = await freePort()
const BASE = 'http://127.0.0.1:' + PORT
const server = spawn(process.execPath, [path.join(root, 'scripts', 'serve-test.js')], {
cwd: root,
env: Object.assign({}, process.env, { IWB_LOCAL_PORT: String(PORT) }),
stdio: ['ignore', 'ignore', 'pipe'],
})
let serverErr = ''
server.stderr.on('data', (d) => { serverErr += String(d) })
const stop = () => { try { server.kill('SIGTERM') } catch (e) { /* ignore */ } }
process.on('SIGINT', () => { stop(); process.exit(130) })
process.on('SIGTERM', () => { stop(); process.exit(143) })
try {
let up = false
for (let i = 0; i < 40; i++) {
if (await ping(BASE)) { up = true; break }
if (server.exitCode !== null) break
await wait(250)
}
if (!up) {
console.error('[e2e-smoke] 测试服没起来(端口 ' + PORT + ')' + (serverErr ? '\n' + serverErr.slice(0, 400) : ''))
return 1
}
const args = [require.resolve('@playwright/test/cli'), 'test', ...SPECS, '--reporter=line', '--workers=4']
const code = await new Promise((resolve) => {
const pw = spawn(process.execPath, args, {
cwd: root,
env: Object.assign({}, process.env, { IWB_BASE_URL: BASE }),
stdio: 'inherit',
})
pw.on('exit', (c) => resolve(c == null ? 1 : c))
})
if (code !== 0) {
console.error('[e2e-smoke] 冒烟失败(exit ' + code + ')')
if (serverErr) console.error('[e2e-smoke] 测试服 stderr:' + String.fromCharCode(10) + serverErr.slice(0, 800))
if (server.exitCode !== null) console.error('[e2e-smoke] 测试服已退出,exitCode=' + server.exitCode)
}
return code
} finally {
stop()
await wait(150)
}
}
main().then((code) => process.exit(code)).catch((e) => {
console.error('[e2e-smoke] ' + (e && e.message))
process.exit(1)
})