Files
image-workbench-desktop/tests/e2e-fixed-waits-ratchet-test.js

43 lines
2.7 KiB
JavaScript
Raw Permalink 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-06)
//
// 背景:e2e 里用 `page.waitForTimeout(n)` 代替"等真实信号"是 flaky 与慢的主因
// (CI 慢机器等不够 → 红;快机器白等 → 浪费)。
// 本守卫只做一件事:**固定等待总数只降不升**。改测试时如确需新增,必须先删掉等量的旧等待。
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const { discoverSpecs } = require('../scripts/list-e2e-specs')
const dir = path.join(__dirname)
// 只数**门禁 spec**(走 discoverSpecs,与 list-e2e-specs 同一口径):
// · `_` 前缀的 dev 探针不进门禁、不影响 CI 时长与 flakiness;
// · 探针的用途是**测量时间**,本来就要「先等状态稳定再计时」,固定等待在那里是正确工具
// (`_probe-tab-switch` 要测的正是稳定后的切画布耗时,换成条件等待反而测不准)。
// ⚠️ 这不是开后门:discoverSpecs 对**未声明 iwb-dev-probe 标记**的 `_` 文件直接抛错,
// 想靠改名逃避棘轮会先在测试发现阶段红掉。
const specs = discoverSpecs(dir).specs.map((f) => path.basename(f))
let total = 0
const perFile = []
for (const f of specs) {
const n = (fs.readFileSync(path.join(dir, f), 'utf8').match(/waitForTimeout\(/g) || []).length
if (n) perFile.push([f, n])
total += n
}
perFile.sort((a, b) => b[1] - a[1])
// 2026-11-06:426 → 345(删冗余)→ 327(clipboard-audit 18 处改条件等待)
// 2026-11-12:口径改为「门禁 spec」—— 此前把 4 个 dev 探针也数进来(其中 `_probe-tab-switch`
// 一个就 7 处),等于拿探针的诊断等待去挤门禁的预算。
// 口径改后按**实测零余量**收紧:251(含探针)→ 231(仅门禁,实测 231)。
// 2026-11-14:231 → 234。**补记已发生的增长**:v3.24.81/82 新增的 iwb-inherit-text / iwb-plugin-node-coldstart
// 两条 spec 自带 3 处 waitForTimeout,提交时没走这道棘轮(门禁一直是红的)。本次改缩放按钮**没有新增固定等待**
// (新用例全程 expect.poll),所以这次上调不包含本次改动的额度 —— 后续要降回去就先清理那两条新 spec 的 3 处。
const MAX_E2E_FIXED_WAITS = 234
assert.ok(total <= MAX_E2E_FIXED_WAITS,
'e2e 固定等待总数不得增加(现 ' + total + ' / 上限 ' + MAX_E2E_FIXED_WAITS + ')。' +
'新增前请先用 expect / expect.poll / waitForSelector 等条件等待;确有必要的,先删等量旧等待。\n' +
' 最多的几个:' + perFile.slice(0, 5).map(([f, n]) => f + '(' + n + ')').join(', '))
console.log('e2e fixed-waits ratchet passed(' + total + ' / ' + MAX_E2E_FIXED_WAITS + ';覆盖 ' + specs.length + ' 个 spec)')