Files
image-workbench-desktop/tests/list-e2e-specs-test.js
T

67 lines
4.0 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 门禁 spec 必须**自动发现**,不允许再出现"新 spec 被静默漏跑"。
// 见 scripts/list-e2e-specs.js 与 docs/standards/project-engineering-standards.md §13.20。
const assert = require('assert')
const fs = require('fs')
const os = require('os')
const path = require('path')
const { discoverSpecs, PROBE_MARKER } = require('../scripts/list-e2e-specs')
const root = path.resolve(__dirname, '..')
const testsDir = path.join(root, 'tests')
const all = fs.readdirSync(testsDir).filter((name) => name.endsWith('.spec.js')).sort()
const expectedSpecs = all.filter((name) => !name.startsWith('_'))
const expectedExcluded = all.filter((name) => name.startsWith('_'))
const result = discoverSpecs(testsDir)
const specsBase = result.specs.map((file) => path.basename(file))
const excludedBase = result.excluded.map((file) => path.basename(file))
// 门禁集合 = 磁盘上全部「非下划线前缀」spec(逐个核对,顺序也钉住)
assert.deepStrictEqual(specsBase, expectedSpecs, '门禁 spec 必须等于全部非下划线前缀的 spec')
// 当前门禁规模钉死:若新增 spec 请同步更新此数字(它让"门禁悄悄变小"立刻可见)
// 45 = 44 + iwb-plugin-panel-tab-leak(插件面板切 tab 残留守护)
// 51 = 50 + iwb-tabs-release(多标签释放语义:回首页不降级 / 关标签先保存再关 / 彻底删除连带关标签)
// 52 = 51 + iwb-lod(LOD 判据:fit 大画布不渲染完整节点体 / 放大后恢复 / 常规画布不 LOD)
// 54 = 52 + iwb-inherit-text(v3.24.81 上游继承文本)+ iwb-plugin-node-coldstart(v3.24.82 插件节点体异步注册)
// —— 这两条 spec 随 v3.24.81/82 一起进仓库时没同步更新本数字,门禁从那时起是红的(2026-11-14 补记)
// 55 = 54 + iwb-multi-tab(v3.24.85:跨标签页契约 —— A 页 flush 落盘后 B 页靠 rev 轮询可见 / 图库归档受跨进程锁保护)
assert.strictEqual(result.specs.length, 55, '当前门禁应自动发现 55 个 spec(新增 iwb-multi-tab)')
// 排除集合 = 全部人工 dev 探针,且都必须已声明标记
// 4 = 3 + _probe-tab-switch(切画布标签耗时归因:四轮对照实验,只读诊断)
assert.deepStrictEqual(excludedBase, ['_perf-baseline.spec.js', '_plugin-host-probe.spec.js', '_probe-drag.spec.js', '_probe-tab-switch.spec.js'], '被排除的应是全部带 iwb-dev-probe 标记的 dev 探针')
// 结构不变量:两集合无交集 + 并集 == 磁盘上全部 spec
assert.strictEqual(result.specs.length + result.excluded.length, all.length, 'specs + excluded 必须等于磁盘全部')
const union = new Set([...specsBase, ...excludedBase])
assert.strictEqual(union.size, all.length, 'specs ∪ excluded 必须恰好等于磁盘全部 spec(无重复、无遗漏)')
// 回归护栏:加入一个「未声明标记」的 _ 前缀 spec 必须让 discoverSpecs 抛错(否则"静默排除"会回来)
const fixture = fs.mkdtempSync(path.join(os.tmpdir(), 'iwb-e2e-specs-'))
try {
fs.writeFileSync(path.join(fixture, 'a.spec.js'), '// 正常 spec\n')
fs.writeFileSync(path.join(fixture, '_probe.spec.js'), '// 没有标记\n')
assert.throws(() => discoverSpecs(fixture), /iwb-dev-probe/, '未标记的 _ 前缀 spec 必须抛错')
} finally {
fs.rmSync(fixture, { recursive: true, force: true })
}
// 补上标记后应被"排除"而不是抛错
const fixture2 = fs.mkdtempSync(path.join(os.tmpdir(), 'iwb-e2e-specs-'))
try {
fs.writeFileSync(path.join(fixture2, 'a.spec.js'), '// 正常 spec\n')
fs.writeFileSync(path.join(fixture2, '_probe.spec.js'), `// ${PROBE_MARKER}: dev 探针\n`)
const discovered = discoverSpecs(fixture2)
assert.strictEqual(discovered.specs.length, 1, '带标记的探针不该进门禁')
assert.strictEqual(discovered.excluded.length, 1, '带标记的探针应被排除')
assert.strictEqual(path.basename(discovered.excluded[0]), '_probe.spec.js')
} finally {
fs.rmSync(fixture2, { recursive: true, force: true })
}
console.log('list-e2e-specs checks passed')