Files
image-workbench-desktop/tests/edge-graph-performance-test.js

26 lines
1.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'
// ⚠️ **这不是性能测试** —— 文件名里的 "performance" 指的是「这段实现是为性能而写的」,
// 而本用例本身**只做源码文本契约检查**(断言 app.js 里有某段实现/某处写法),
// **不测量任何耗时/帧率/内存**。
//
// 为什么要有这个文件:守住「性能相关的实现选择」不被后来的重构悄悄改掉
// (例:拖动必须走 DOM transform 而非逐帧 setNodes,否则大画布每帧 O(n) 重渲染)。
// 真实性能回归由 e2e 性能用例与 `tests/_perf-baseline.spec.js` 探针负责。
//
// 副作用(已知):这类断言**锁死了实现文本**,重构会打红 —— 故受
// `tests/source-text-ratchet-test.js` 的「只减不增」棘轮约束(新增源码文本钉点会被拦)。
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const source = fs.readFileSync(path.join(__dirname, '..', 'app.js'), 'utf8')
// P1 拆分批 3(2026-10-28):computeEdgePath 已迁到 src/canvas-geometry.js。
// 依赖图索引 / 来源排序这两条钉点改读新模块,保护语义不变(仍是「连线路径只走图索引、不扫全量 edges」)。
const geometrySrc = fs.readFileSync(path.join(__dirname, '..', 'src', 'canvas-geometry.js'), 'utf8')
assert.ok(geometrySrc.includes("graph && graph.incomingByNode.get(dst.id)") || geometrySrc.includes("canvasGraph.incomingByNode.get(dst.id)"))
assert.ok(geometrySrc.includes('.sort(compareCanvasTextOrder)'))
assert.ok(!source.includes("const bsrcs = refs.edges.filter((e) => e.to === dst.id).map((e) => refs.nodes.find"))
assert.ok(!source.includes('edgeSourceFilter'))
console.log('edge graph performance checks passed')