Files
image-workbench-desktop/scripts/e2e-known-red-report.js
T

58 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict'
/* e2e 已知红报告(2026-11-24)
*
* 为什么需要:57 个 spec 里有 16 条长期红(环境性 8 + 真缺陷 8),
* 没有清单时「全绿」和「红了」都不可信 —— 新红会被旧红淹没。
*
* 用法:先起测试服,然后
* node scripts/e2e-known-red-report.js 只跑清单内的 spec
* node scripts/e2e-known-red-report.js --all 跑全部 spec(慢,谨慎)
*
* 退出码:0 = 失败数不超过清单(或更少);1 = 出现**新增**失败(需要人看)。
* 注意:本脚本不进 verify:ci(e2e 只在 PR 跑,省 CI 额度)。
*/
const fs = require('fs')
const path = require('path')
const { execFileSync } = require('child_process')
const root = path.resolve(__dirname, '..')
const list = JSON.parse(fs.readFileSync(path.join(root, 'tests', 'fixtures', 'e2e-known-red.json'), 'utf8'))
const only = process.argv.includes('--all') ? null : list.entries.map((e) => e.spec)
function runSpec (spec) {
const args = ['test', spec, '--reporter=line']
try {
const out = execFileSync('npx', args, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })
return { failed: 0, tail: out.trim().split('\n').slice(-2).join(' | ') }
} catch (e) {
const out = String((e && e.stdout) || '') + String((e && e.stderr) || '')
const m = /(\d+) failed/.exec(out)
return { failed: m ? Number(m[1]) : -1, tail: out.trim().split('\n').slice(-2).join(' | ') }
}
}
let worst = 0
const rows = []
const targets = only || fs.readdirSync(path.join(root, 'tests')).filter((f) => f.endsWith('.spec.js')).map((f) => 'tests/' + f)
for (const spec of targets) {
const known = list.entries.find((e) => e.spec === spec)
const r = runSpec(spec)
const allowed = known ? known.knownFailures : 0
const delta = r.failed - allowed
if (delta > 0) worst = Math.max(worst, delta)
rows.push({ spec, failed: r.failed, allowed, delta, kind: known ? known.kind : 'unlisted' })
}
console.log('\ne2e 已知红对照(基线 ' + list.measuredVersion + ' · ' + list.measuredAt + ')\n')
console.log('spec'.padEnd(46) + 'now'.padEnd(6) + 'known'.padEnd(7) + 'delta')
for (const r of rows) {
const mark = r.delta > 0 ? ' ← 新增红' : (r.failed === 0 && r.allowed > 0 ? ' ← 已修复,可移出清单' : '')
console.log(r.spec.padEnd(46) + String(r.failed).padEnd(6) + String(r.allowed).padEnd(7) + (r.delta > 0 ? '+' + r.delta : String(r.delta)) + mark)
}
if (worst > 0) {
console.log('\n有新增失败:请判断是回归还是清单过期(修好后记得删条目)。')
process.exit(1)
}
console.log('\n没有新增失败。')