5111858346
同一棵树只翻 main.ts/App.vue 做 A/B(其余文件两轮一致,差值可整份归给这条): 入口 JS −34.7%、CSS −45.6%、dist 整树 −567,203 B;A 组跑两次字节与哈希完全相同。 新增 src/plugins/element.ts 显式注册表。没走用户端那套 ElementPlusResolver: 自动引入会把"到底注册了哪些组件"藏进产物,而按需注册的失败模式恰恰是 "漏一个组件不报错、页面渲染成裸标签",只有显式清单才能让护栏从源码推标签 做双向比对。语言包随之换到 App.vue 的 el-config-provider。 顺带摘掉两处重复请求:去重页 reAnalyze 白拉又丢返回值的那次整集 console、 看板 30s 心跳里无条件重拉的店铺候选(后端 SELECT DISTINCT 无缓存的字典数据)。 护栏 10 例(标签清单由 .vue 源码推导,不是手写名单)+ 变异自证 9/9 全杀; 前端全量 node --test 1698 例 0 红。只欠逐页浏览器视觉验证 —— 按需引入最坏的 那类回归不会让构建变红。
58 lines
3.1 KiB
TypeScript
58 lines
3.1 KiB
TypeScript
import test from 'node:test'
|
||
import assert from 'node:assert/strict'
|
||
import { readSource, occurrences } from './helpers.ts'
|
||
|
||
// 10-04 三端性能审计(我逐行核过的两条重复请求):
|
||
// ① DuplicateCheckPage.reAnalyze() 先 await fetchDuplicateConsole(全空参数) 把返回值丢掉,
|
||
// 再 loadConsole() 拉一次 —— 服务端 console 端点纯读(loadLatest 按行号缓存,无"预热"必要),
|
||
// 所以那一次是白跑的整集查询。
|
||
// ② TaskCenterBoardPage.refreshAll() 的 Promise.all 里无条件带 loadShopOptions(),
|
||
// 而它是 30s 心跳(POLL_INTERVAL_MS)走的同一条函数 —— 店铺候选是字典数据
|
||
// (后端 SELECT DISTINCT 无缓存),进热路径等于每轮心跳多打一次全库去重。
|
||
// 两条都用「排他 + 精确锚」断言:既钉住修好的形状,也钉住"旧的无条件写法"不得回流。
|
||
|
||
/** 取顶层函数体(从签名后的第一个 { 到配对的 })。 */
|
||
function functionBody(source: string, signature: string): string {
|
||
const start = source.indexOf(signature)
|
||
assert.notEqual(start, -1, `源码里找不到 ${signature}`)
|
||
const open = source.indexOf('{', start + signature.length)
|
||
assert.notEqual(open, -1, `${signature} 后面没有函数体`)
|
||
let depth = 0
|
||
for (let i = open; i < source.length; i += 1) {
|
||
if (source[i] === '{') depth += 1
|
||
else if (source[i] === '}') {
|
||
depth -= 1
|
||
if (depth === 0) return source.slice(open + 1, i)
|
||
}
|
||
}
|
||
assert.fail(`${signature} 的函数体括号没闭合`)
|
||
}
|
||
|
||
test('perf_dup_reanalyze_does_not_fetch_console_twice', () => {
|
||
const page = readSource('src/pages/tasks/DuplicateCheckPage.vue')
|
||
const body = functionBody(page, 'async function reAnalyze(')
|
||
// 丢弃返回值的整集查询必须消失(修复前正是这一行让它翻倍)
|
||
assert.equal(occurrences(body, 'fetchDuplicateConsole('), 0,
|
||
'reAnalyze 不应自己再拉一次 duplicate-check-console')
|
||
assert.equal(occurrences(body, 'loadConsole('), 1,
|
||
'reAnalyze 只经 loadConsole() 拉一次')
|
||
})
|
||
|
||
test('perf_board_shop_options_stay_out_of_heartbeat', () => {
|
||
const board = readSource('src/pages/task-center/TaskCenterBoardPage.vue')
|
||
const body = functionBody(board, 'async function refreshAll(')
|
||
assert.ok(/silent\s*.*loadShopOptions/s.test(body.split('\n').filter((l) => /loadShopOptions/.test(l)).join('\n')),
|
||
'loadShopOptions 必须由 silent 分档,只在进页/手动刷新/切页签时重拉')
|
||
// 无条件那一行(修复前的形状)不得回流
|
||
assert.equal(occurrences(body, '\n loadShopOptions(),'), 0,
|
||
'refreshAll 里不得保留无条件的 loadShopOptions() 直列')
|
||
})
|
||
|
||
test('perf_board_heartbeat_is_the_silent_path', () => {
|
||
// 上一那条断言只有"心跳确实走 silent"才成立;这里钉住这个前提本身。
|
||
const board = readSource('src/pages/task-center/TaskCenterBoardPage.vue')
|
||
assert.match(board, /setInterval\([\s\S]{0,200}refreshAll\(true\)[\s\S]{0,200}POLL_INTERVAL_MS/,
|
||
'30s 心跳必须以 silent=true 调 refreshAll')
|
||
assert.match(board, /POLL_INTERVAL_MS = 30_000/, '心跳周期仍是 30s(改动没顺手调周期)')
|
||
})
|