dsh-postapi 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +139 -2
  3. package/cordis.patch.yml +3 -0
  4. package/dist/client.js +5651 -0
  5. package/docs/DETAIL.md +27 -0
  6. package/docs/apifox-design-spec.md +101 -0
  7. package/docs/apifox-research/analysis.md +254 -0
  8. package/docs/apifox-ui-delivery.md +150 -0
  9. package/docs/apifox-visual-parity-spec.md +353 -0
  10. package/docs/feature-matrix.md +112 -0
  11. package/docs/flow-reference/sequence-reference.html +163 -0
  12. package/docs/interface-contract-v2.md +175 -0
  13. package/docs/interface-contract.md +105 -0
  14. package/docs/nav-layout-v2-spec.md +107 -0
  15. package/docs/preview.svg +9 -0
  16. package/docs/probe-client.legacy.js +31 -0
  17. package/docs/rootcause-sidebar-vanish.md +95 -0
  18. package/docs/rootcause.md +86 -0
  19. package/docs/sidebar-notes.md +153 -0
  20. package/docs/ui-audit.md +197 -0
  21. package/docs/ui-notes.md +98 -0
  22. package/docs/v2-delivery.md +99 -0
  23. package/icon.svg +4 -0
  24. package/index.js +5 -0
  25. package/locale/en.json +7 -0
  26. package/locale/zh.json +7 -0
  27. package/package.json +73 -4
  28. package/src/client/index.js +132 -0
  29. package/src/client/jsx-shim.js +9 -0
  30. package/src/client/pages/__tests__/heights.test.js +135 -0
  31. package/src/client/pages/components/AssertTable.jsx +122 -0
  32. package/src/client/pages/components/BodyEditor.jsx +91 -0
  33. package/src/client/pages/components/EmptyState.jsx +52 -0
  34. package/src/client/pages/components/FolderTree.jsx +109 -0
  35. package/src/client/pages/components/JsonEditor.jsx +45 -0
  36. package/src/client/pages/components/ParamTable.jsx +226 -0
  37. package/src/client/pages/components/ResponsePanel.jsx +278 -0
  38. package/src/client/pages/components/ScriptPanel.jsx +99 -0
  39. package/src/client/pages/components/StatusPill.jsx +35 -0
  40. package/src/client/pages/components/__tests__/apifox-ui.test.js +291 -0
  41. package/src/client/pages/components/__tests__/pages-a.test.js +392 -0
  42. package/src/client/pages/components/__tests__/tree.test.js +379 -0
  43. package/src/client/pages/components/headerPresets.js +63 -0
  44. package/src/client/pages/debug.jsx +576 -0
  45. package/src/client/pages/design-tokens.css +2604 -0
  46. package/src/client/pages/doc.jsx +552 -0
  47. package/src/client/pages/env.jsx +378 -0
  48. package/src/client/pages/flow.jsx +349 -0
  49. package/src/client/pages/history.jsx +238 -0
  50. package/src/client/pages/import.jsx +396 -0
  51. package/src/client/pages/mock.jsx +316 -0
  52. package/src/client/pages/overview.jsx +348 -0
  53. package/src/client/pages/schema.jsx +317 -0
  54. package/src/client/pages/search.jsx +216 -0
  55. package/src/client/pages/sequence.jsx +344 -0
  56. package/src/client/pages/settings.jsx +205 -0
  57. package/src/client/pages/test.jsx +470 -0
  58. package/src/client/pages/theme.js +27 -0
  59. package/src/client/pages-entry.js +20 -0
  60. package/src/client/shell/ApiTitle.js +19 -0
  61. package/src/client/shell/Body.js +492 -0
  62. package/src/client/shell/definition.js +57 -0
  63. package/src/client/shell/locales.js +185 -0
  64. package/src/client/shell/menu.js +174 -0
  65. package/src/client/shell/registry.js +530 -0
  66. package/src/host/bridge.js +407 -0
  67. package/src/host/codegen.js +356 -0
  68. package/src/host/import-export.js +1044 -0
  69. package/src/host/index.js +102 -0
  70. package/src/host/mock-server.js +303 -0
  71. package/src/host/request.js +336 -0
  72. package/src/host/script-sandbox.js +272 -0
  73. package/src/host/storage.js +803 -0
  74. package/src/host/test-runner.js +126 -0
  75. package/src/host/variables.js +108 -0
@@ -0,0 +1,392 @@
1
+ // pages-a.test.js — pages-a 三页(doc / debug / mock)与共用组件的静态 + 行为测试
2
+ // 双模式:node 直跑(自建 mini runner)或由 lead 的 tests/run.js 收录(导出 tests 数组)。
3
+ // 行为测试不引 react-dom:用 esbuild 把页面打成 cjs(external react + jsx-shim),
4
+ // 在 vm 里用假 react 加载,取导出纯函数真跑(不渲染)。
5
+ import { readFileSync, existsSync } from 'node:fs'
6
+ import { fileURLToPath } from 'node:url'
7
+ import { dirname, join, resolve } from 'node:path'
8
+ import { createRequire } from 'node:module'
9
+ import vm from 'node:vm'
10
+ // Apifox 化专项用例(doc/debug 两页 + 四组件):独立文件便于单跑,这里拼进同一套件,
11
+ // 使 tests/run.js 的 pages-a 收录点自动覆盖(run.js 属 lead 范围,不新增收录行)。
12
+ import { tests as apifoxUiTests } from './apifox-ui.test.js'
13
+
14
+ const __dirname = dirname(fileURLToPath(import.meta.url))
15
+ const COMPONENTS_DIR = resolve(__dirname, '..')
16
+ const PAGES_DIR = resolve(COMPONENTS_DIR, '..')
17
+ const ROOT = resolve(PAGES_DIR, '..', '..', '..')
18
+
19
+ const PAGE_FILES = {
20
+ doc: join(PAGES_DIR, 'doc.jsx'),
21
+ debug: join(PAGES_DIR, 'debug.jsx'),
22
+ mock: join(PAGES_DIR, 'mock.jsx'),
23
+ }
24
+ const COMPONENT_FILES = ['EmptyState.jsx', 'StatusPill.jsx', 'ParamTable.jsx', 'JsonEditor.jsx', 'FolderTree.jsx']
25
+
26
+ const read = (file) => (existsSync(file) ? readFileSync(file, 'utf8') : '')
27
+
28
+ function assert(cond, message) {
29
+ if (!cond) throw new Error(message)
30
+ }
31
+
32
+ /* ---------------- esbuild + vm:加载页面模块取导出纯函数 ---------------- */
33
+
34
+ function loadEsbuild() {
35
+ const candidates = [ROOT, join(ROOT, '.research', 'sidebar')]
36
+ for (const dir of candidates) {
37
+ if (existsSync(join(dir, 'node_modules', 'esbuild'))) {
38
+ return createRequire(join(dir, 'noop.js'))('esbuild')
39
+ }
40
+ }
41
+ throw new Error('esbuild 不可用(工作区与 .research/sidebar 均未安装)')
42
+ }
43
+
44
+ const fakeReact = {
45
+ createElement: (type, props, ...children) => ({ type, props, children }),
46
+ Fragment: 'Fragment',
47
+ useState: (v) => [typeof v === 'function' ? v() : v, () => {}],
48
+ useEffect: () => {},
49
+ useRef: (v) => ({ current: v }),
50
+ useMemo: (fn) => fn(),
51
+ useCallback: (fn) => fn(),
52
+ useLayoutEffect: () => {},
53
+ }
54
+
55
+ async function loadPageModule(file) {
56
+ const esbuild = loadEsbuild()
57
+ const built = await esbuild.build({
58
+ entryPoints: [file],
59
+ bundle: true,
60
+ write: false,
61
+ format: 'cjs',
62
+ platform: 'browser',
63
+ target: ['es2022'],
64
+ jsx: 'transform',
65
+ inject: [join(ROOT, 'src', 'client', 'jsx-shim.js')],
66
+ loader: { '.js': 'jsx' },
67
+ external: ['react'],
68
+ logLevel: 'silent',
69
+ })
70
+ const code = built.outputFiles[0].text
71
+ const module = { exports: {} }
72
+ const sandbox = {
73
+ window: { __postapiQueue: [] },
74
+ module,
75
+ exports: module.exports,
76
+ console,
77
+ require: (name) => {
78
+ if (name === 'react') return fakeReact
79
+ throw new Error('意外的宿主 require: ' + name)
80
+ },
81
+ }
82
+ vm.createContext(sandbox)
83
+ vm.runInContext(code, sandbox, { filename: file })
84
+ return { exports: module.exports, queue: sandbox.window.__postapiQueue }
85
+ }
86
+
87
+ /* ---------------- 静态规则 ---------------- */
88
+
89
+ const BANNED_APIS = [/\balert\s*\(/, /\bconfirm\s*\(/, /\bprompt\s*\(/]
90
+ const HARDCODED_COLOR = /#[0-9a-fA-F]{3}(?:[0-9a-fA-F]{3})?\b|\brgba?\s*\(|\bhsla?\s*\(/
91
+ const HARDCODED_FONT = /fontSize\s*:\s*['"?]?\d/
92
+ const HEIGHT_RE = new RegExp('\\b(minHeight|maxHeight|height)\\s*:\\s*[\'"\x60]([^\'"\x60]+)[\'"\x60]', 'g')
93
+ const HEIGHT_OK = /^var\(--(ctl|row|pill)-h\)$/
94
+ const HEIGHT_AUTO = new Set(['100%', 'auto', 'inherit', 'fit-content', 'min-content', 'max-content'])
95
+ const BRIDGE_FETCH = new RegExp('fetch\\(\\s*[\'"\x60]/dsh-postapi')
96
+
97
+ function heightViolations(src, label) {
98
+ const bad = []
99
+ let m
100
+ HEIGHT_RE.lastIndex = 0
101
+ while ((m = HEIGHT_RE.exec(src))) {
102
+ const value = String(m[2]).trim()
103
+ if (HEIGHT_OK.test(value) || HEIGHT_AUTO.has(value)) continue
104
+ if (/^calc\(/.test(value) && /var\(--(ctl|row|pill)-h\)|100%/.test(value)) continue
105
+ const line = src.slice(0, m.index).split('\n').length
106
+ bad.push(label + ':' + line + ' ' + m[1] + ':' + value)
107
+ }
108
+ return bad
109
+ }
110
+
111
+ /* ---------------- 测试集 ---------------- */
112
+
113
+ const PAGE_SPECS = [
114
+ { name: 'doc', exportName: 'DocPage' },
115
+ { name: 'debug', exportName: 'DebugPage' },
116
+ { name: 'mock', exportName: 'MockPage' },
117
+ ]
118
+
119
+ const pagesATests = [
120
+ {
121
+ name: 'pages-a: 三页文件存在且首部自注册到 __postapiQueue',
122
+ fn() {
123
+ for (const spec of PAGE_SPECS) {
124
+ const src = read(PAGE_FILES[spec.name])
125
+ assert(src !== '', spec.name + '.jsx 不存在')
126
+ const re = new RegExp("__postapiQueue[^\\n]*\\.push\\(\\['" + spec.name + "'")
127
+ assert(re.test(src), spec.name + '.jsx 缺少 push([\'' + spec.name + '\', ...]) 自注册')
128
+ assert(
129
+ new RegExp('export function ' + spec.exportName).test(src),
130
+ spec.name + '.jsx 缺少命名导出 ' + spec.exportName,
131
+ )
132
+ }
133
+ },
134
+ },
135
+ {
136
+ name: 'pages-a: 页面根元素为 pp-scope pp-page + data-page + applyTheme',
137
+ fn() {
138
+ for (const spec of PAGE_SPECS) {
139
+ const src = read(PAGE_FILES[spec.name])
140
+ // 根类必须是 pp-scope 起头,且带 pp-page 或 pp-page-flush
141
+ // (doc/debug 是 Apifox 三段式/调试台,用 pp-page-flush 取消外层内边距,排版交给 .pp-body-3col / .pp-debug-layout)
142
+ assert(/className="pp-scope pp-page(-flush)?(\s[^"]*)?"/.test(src), spec.name + '.jsx 根元素缺 pp-scope pp-page(-flush)')
143
+ assert(src.includes('data-page="' + spec.name + '"'), spec.name + '.jsx 根元素缺 data-page')
144
+ assert(/useEffect\(\(\) => applyTheme\(rootRef\.current\)/.test(src), spec.name + '.jsx 未调用 applyTheme')
145
+ }
146
+ },
147
+ },
148
+ {
149
+ name: 'pages-a: 无 alert/confirm/prompt 与硬编码桥 fetch 路径',
150
+ fn() {
151
+ const files = [PAGE_FILES.doc, PAGE_FILES.debug, PAGE_FILES.mock]
152
+ .concat(COMPONENT_FILES.map((f) => join(COMPONENTS_DIR, f)))
153
+ for (const file of files) {
154
+ const src = read(file)
155
+ assert(src !== '', file + ' 不存在')
156
+ for (const re of BANNED_APIS) {
157
+ assert(!re.test(src), file + ' 使用了禁用 API(alert/confirm/prompt)')
158
+ }
159
+ assert(!BRIDGE_FETCH.test(src), file + ' 直接写了桥 fetch 路径')
160
+ }
161
+ },
162
+ },
163
+ {
164
+ name: 'pages-a: 只 import react 与本地相对路径,无 npm 依赖',
165
+ fn() {
166
+ const files = [PAGE_FILES.doc, PAGE_FILES.debug, PAGE_FILES.mock]
167
+ .concat(COMPONENT_FILES.map((f) => join(COMPONENTS_DIR, f)))
168
+ for (const file of files) {
169
+ const src = read(file)
170
+ const re = /from\s+['"]([^'"]+)['"]/g
171
+ let m
172
+ while ((m = re.exec(src))) {
173
+ const spec = m[1]
174
+ const ok = spec === 'react' || spec.charAt(0) === '.'
175
+ assert(ok, file + ' 引入了非白名单模块:' + spec)
176
+ }
177
+ }
178
+ },
179
+ },
180
+ {
181
+ name: 'pages-a: 无内联颜色/字号字面量',
182
+ fn() {
183
+ const files = [PAGE_FILES.doc, PAGE_FILES.debug, PAGE_FILES.mock]
184
+ .concat(COMPONENT_FILES.map((f) => join(COMPONENTS_DIR, f)))
185
+ for (const file of files) {
186
+ const src = read(file)
187
+ assert(!HARDCODED_COLOR.test(src), file + ' 出现颜色字面量(应用 var(--*) token)')
188
+ assert(!HARDCODED_FONT.test(src), file + ' 出现字号字面量(应用 var(--fs-*) token)')
189
+ }
190
+ },
191
+ },
192
+ {
193
+ name: 'pages-a: 内联高度只引用尺寸 token',
194
+ fn() {
195
+ const files = [PAGE_FILES.doc, PAGE_FILES.debug, PAGE_FILES.mock]
196
+ .concat(COMPONENT_FILES.map((f) => join(COMPONENTS_DIR, f)))
197
+ const bad = []
198
+ for (const file of files) bad.push(...heightViolations(read(file), file.replace(ROOT, '')))
199
+ assert(bad.length === 0, '高度未引用 token:\n' + bad.join('\n'))
200
+ },
201
+ },
202
+ {
203
+ name: 'pages-a: api 缺失时渲染 mock 并标注「示例数据」',
204
+ fn() {
205
+ for (const spec of PAGE_SPECS) {
206
+ const src = read(PAGE_FILES[spec.name])
207
+ assert(src.includes('示例数据'), spec.name + '.jsx 未标注「示例数据」')
208
+ assert(/isMock/.test(src), spec.name + '.jsx 缺 isMock 状态')
209
+ }
210
+ },
211
+ },
212
+ {
213
+ name: 'pages-a: doc 页真接 api(listProjects/getProject/saveResponse)且含四组参数表 + TOC + cURL',
214
+ fn() {
215
+ const src = read(PAGE_FILES.doc)
216
+ for (const need of ['listProjects', 'getProject', 'saveResponse']) {
217
+ assert(src.includes(need), 'doc.jsx 未接 storage.' + need)
218
+ }
219
+ for (const sec of ['sec-path', 'sec-params', 'sec-headers', 'sec-cookies', 'sec-body', 'sec-auth', 'sec-response']) {
220
+ assert(src.includes(sec), 'doc.jsx 缺锚点 ' + sec)
221
+ }
222
+ assert(src.includes('ParamTable'), 'doc.jsx 未使用 ParamTable')
223
+ assert(src.includes('复制为 cURL'), 'doc.jsx 缺「复制为 cURL」')
224
+ assert(src.includes('navigator.clipboard'), 'doc.jsx 未走剪贴板 API')
225
+ // v2:右 TOC 改成主区顶部锚点条(.pp-anchor-chip),窄容器里不再吃 240px
226
+ assert(src.includes('pp-anchor-chip'), 'doc.jsx 缺页内锚点条(v2 取代右 TOC)')
227
+ },
228
+ },
229
+ {
230
+ name: 'pages-a: debug 页真接 api(request.send / saveEndpoint)且含状态胶囊与断言列表',
231
+ fn() {
232
+ const src = read(PAGE_FILES.debug)
233
+ assert(src.includes('request') && src.includes('send'), 'debug.jsx 未接 request.send')
234
+ assert(src.includes('saveEndpoint'), 'debug.jsx 未接 storage.saveEndpoint')
235
+ // 状态胶囊与断言结果已随响应面板抽成组件(debug.jsx 只负责传 resp)
236
+ assert(src.includes('ResponsePanel'), 'debug.jsx 未使用 ResponsePanel')
237
+ const respSrc = read(join(COMPONENTS_DIR, 'ResponsePanel.jsx'))
238
+ assert(respSrc.includes('StatusPill'), 'ResponsePanel.jsx 未使用 StatusPill')
239
+ assert(respSrc.includes('resp.tests'), 'ResponsePanel.jsx 缺断言结果列表')
240
+ // Apifox 调试页是单栏(.apiCase padding:10px):接口树由左侧全局导航承担,
241
+ // 页面内不再自带树面板,所以断言单栏容器而不是旧的三栏 .pp-debug-layout。
242
+ assert(src.includes('pp-debug-page'), 'debug.jsx 缺单栏容器 .pp-debug-page')
243
+ assert(!src.includes('pp-debug-layout'), 'debug.jsx 不应再有自带树的三栏布局')
244
+ assert(!src.includes('FolderTree'), 'debug.jsx 不应再自渲染接口树(树在左侧全局导航)')
245
+ assert(src.includes('#/history'), 'debug.jsx 缺历史回放入口')
246
+ for (const tab of ["'params'", "'headers'", "'body'", "'auth'"]) {
247
+ assert(src.includes(tab), 'debug.jsx 缺页签 ' + tab)
248
+ }
249
+ },
250
+ },
251
+ {
252
+ name: 'pages-a: mock 页真接 api(mock.start/stop/status + saveEndpoint)',
253
+ fn() {
254
+ const src = read(PAGE_FILES.mock)
255
+ for (const need of ['mockApi.start', 'mockApi.stop', 'mockApi.status', 'saveEndpoint']) {
256
+ assert(src.includes(need), 'mock.jsx 未接 ' + need)
257
+ }
258
+ assert(src.includes('命中地址'), 'mock.jsx 缺命中地址展示')
259
+ assert(src.includes('延迟'), 'mock.jsx 缺延迟设置')
260
+ },
261
+ },
262
+ {
263
+ name: 'pages-a: buildCurl 生成 method/query/header/auth/body 完整命令',
264
+ async fn() {
265
+ const { exports } = await loadPageModule(PAGE_FILES.doc)
266
+ assert(typeof exports.buildCurl === 'function', 'doc.jsx 未导出 buildCurl')
267
+ const curl = exports.buildCurl({
268
+ method: 'POST',
269
+ url: '/api/v1/orders/{orderId}',
270
+ pathParams: [{ key: 'orderId', value: 'ORD-9', enabled: true }],
271
+ params: [{ key: 'page', value: '2', enabled: true }, { key: 'skip', value: 'x', enabled: false }],
272
+ headers: [{ key: 'Accept', value: 'application/json', enabled: true }],
273
+ auth: { type: 'bearer', token: '{{token}}' },
274
+ body: { type: 'json', content: '{"a":1}' },
275
+ }, 'https://api.example.test')
276
+ assert(curl.includes("curl -X POST 'https://api.example.test/api/v1/orders/ORD-9?page=2'"), 'cURL URL 拼接不正确:' + curl)
277
+ assert(!curl.includes('skip='), 'cURL 不应包含 enabled=false 的参数')
278
+ assert(curl.includes("-H 'Accept: application/json'"), 'cURL 缺 header')
279
+ assert(curl.includes("-H 'Authorization: Bearer {{token}}'"), 'cURL 缺 bearer 认证')
280
+ assert(curl.includes("--data-raw '{\"a\":1}'"), 'cURL 缺 body')
281
+ assert(exports.buildCurl(null, '') === '', 'buildCurl(null) 应返回空串')
282
+ },
283
+ },
284
+ {
285
+ name: 'pages-a: collectVarRefs 收集 {{var}} 且去重;varTable 合并 globals 与环境',
286
+ async fn() {
287
+ const { exports } = await loadPageModule(PAGE_FILES.debug)
288
+ assert(typeof exports.collectVarRefs === 'function', 'debug.jsx 未导出 collectVarRefs')
289
+ assert(typeof exports.varTable === 'function', 'debug.jsx 未导出 varTable')
290
+ const refs = exports.collectVarRefs({
291
+ url: '/x/{{id}}/{{id}}',
292
+ params: [{ key: 'q', value: '{{kw}}' }],
293
+ headers: [],
294
+ body: { content: '{"t":"{{token}}"}' },
295
+ auth: { token: '{{authToken}}' },
296
+ })
297
+ assert(JSON.stringify(refs) === JSON.stringify(['id', 'kw', 'token', 'authToken']), '变量收集结果不符:' + JSON.stringify(refs))
298
+ assert(JSON.stringify(exports.collectVarRefs(null)) === '[]', 'collectVarRefs(null) 应为空数组')
299
+
300
+ const project = {
301
+ globals: { variables: [{ key: 'g', value: '1', enabled: true }, { key: 'off', value: 'x', enabled: false }] },
302
+ environments: [
303
+ { id: 'env_a', name: 'A', baseUrl: 'https://a.test', isDefault: false, variables: [{ key: 'a', value: '2', enabled: true }] },
304
+ { id: 'env_b', name: 'B', baseUrl: 'https://b.test', isDefault: true, variables: [{ key: 'a', value: '3', enabled: true }] },
305
+ ],
306
+ }
307
+ const explicit = exports.varTable(project, 'env_a')
308
+ assert(explicit.table.g === '1' && explicit.table.a === '2', '指定环境未生效:' + JSON.stringify(explicit.table))
309
+ assert(explicit.table.off === undefined, 'enabled=false 的变量不应进入表')
310
+ const fallback = exports.varTable(project, '不存在')
311
+ assert(fallback.env.id === 'env_b', '缺省应回落 isDefault 环境')
312
+ assert(fallback.table.a === '3', '默认环境变量值不正确')
313
+ },
314
+ },
315
+ {
316
+ name: 'pages-a: prettyJson 美化合法 JSON 且原文回落非法 JSON',
317
+ async fn() {
318
+ const { exports } = await loadPageModule(PAGE_FILES.debug)
319
+ assert(typeof exports.prettyJson === 'function', 'debug.jsx 未导出 prettyJson')
320
+ assert(exports.prettyJson('{"a":1}') === '{\n "a": 1\n}', 'prettyJson 美化结果不正确')
321
+ assert(exports.prettyJson('not json') === 'not json', 'prettyJson 非法 JSON 应回落原文')
322
+ assert(exports.prettyJson(null) === '', 'prettyJson(null) 应为空串')
323
+ },
324
+ },
325
+ {
326
+ name: 'pages-a: hitUrls 生成两种命中地址形态',
327
+ async fn() {
328
+ const { exports } = await loadPageModule(PAGE_FILES.mock)
329
+ assert(typeof exports.hitUrls === 'function', 'mock.jsx 未导出 hitUrls')
330
+ const urls = exports.hitUrls('proj_1', { id: 'ep_1', url: '/api/v1/orders' }, 4010)
331
+ assert(urls.length === 2, '命中地址应为 2 条')
332
+ assert(urls[0] === 'http://127.0.0.1:4010/mock/proj_1/ep_1', '按 endpointId 命中地址不正确:' + urls[0])
333
+ assert(urls[1] === 'http://127.0.0.1:4010/mock/proj_1/api/v1/orders', '按 path 命中地址不正确:' + urls[1])
334
+ assert(exports.hitUrls('', null, 4010).length === 0, '缺 projectId/endpoint 应返回空数组')
335
+ },
336
+ },
337
+ {
338
+ name: 'pages-a: statusTone 按 2xx/3xx/4xx 分级且 0 视为错误',
339
+ async fn() {
340
+ const { exports } = await loadPageModule(join(COMPONENTS_DIR, 'StatusPill.jsx'))
341
+ assert(typeof exports.statusTone === 'function', 'StatusPill.jsx 未导出 statusTone')
342
+ assert(exports.statusTone(200) === 'var(--success)', '2xx 应为 success')
343
+ assert(exports.statusTone(302) === 'var(--warning)', '3xx 应为 warning')
344
+ assert(exports.statusTone(404) === 'var(--error)', '4xx 应为 error')
345
+ assert(exports.statusTone(0) === 'var(--error)', '0 应为 error')
346
+ assert(exports.statusTone(undefined) === 'var(--error)', 'undefined 应为 error')
347
+ },
348
+ },
349
+ {
350
+ name: 'pages-a: 三页在 vm 中注册进 __postapiQueue 且导出组件为函数',
351
+ async fn() {
352
+ for (const spec of PAGE_SPECS) {
353
+ const { exports, queue } = await loadPageModule(PAGE_FILES[spec.name])
354
+ const entry = queue.find((e) => e[0] === spec.name)
355
+ assert(Boolean(entry), spec.name + ' 未 push 到 __postapiQueue')
356
+ assert(typeof entry[1] === 'function', spec.name + ' 注册项不是组件函数')
357
+ assert(typeof exports[spec.exportName] === 'function', spec.name + ' 导出 ' + spec.exportName + ' 不是函数')
358
+ }
359
+ },
360
+ },
361
+ ]
362
+
363
+ export const tests = [...pagesATests, ...apifoxUiTests]
364
+
365
+ /* ---------------- mini runner ---------------- */
366
+
367
+ const isMain = (() => {
368
+ try {
369
+ const argv1 = process.argv[1]
370
+ return Boolean(argv1) && resolve(argv1) === fileURLToPath(import.meta.url)
371
+ } catch {
372
+ return false
373
+ }
374
+ })()
375
+
376
+ if (isMain) {
377
+ let passed = 0
378
+ let failed = 0
379
+ for (const t of tests) {
380
+ try {
381
+ await t.fn()
382
+ passed += 1
383
+ console.log('PASS ' + t.name)
384
+ } catch (err) {
385
+ failed += 1
386
+ console.log('FAIL ' + t.name)
387
+ console.log(' ' + (err && err.message ? err.message : err))
388
+ }
389
+ }
390
+ console.log('\npages-a.test:通过 ' + passed + ',失败 ' + failed + ',共 ' + (passed + failed))
391
+ process.exit(failed === 0 ? 0 : 1)
392
+ }