From 08315058547b8b79999bd4de615a6cd3b8b4b2f3 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Thu, 3 Sep 2026 12:04:41 +0800 Subject: [PATCH] =?UTF-8?q?test(lib-guards):=20lib=20=E4=BA=A7=E7=89=A9?= =?UTF-8?q?=E7=BC=BA=E5=A4=B1=E6=97=B6=20chunk-artifact=20/=20manifest-con?= =?UTF-8?q?sistency=20=E8=B7=B3=E8=BF=87=E8=80=8C=E9=9D=9E=20ENOENT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fresh clone 未 build 直接 pnpm test 时,两 spec 的 readFileSync 会 ENOENT 崩溃(此前靠 package.json prepare 钩子隐式兜底)。改为文件级 describe.skipIf 守卫:缺产物时整套显示为 skipped 并 console 提示先 pnpm build(exit 0);产物存在时行为与之前完全一致(本仓 prepare 钩 子产出 lib 后两 spec 照常执行,已验证 9 passed 非 skipped)。 --- tests/chunk-artifact.spec.ts | 13 +++++++++++-- tests/manifest-consistency.spec.ts | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/chunk-artifact.spec.ts b/tests/chunk-artifact.spec.ts index 687d671..ec39364 100644 --- a/tests/chunk-artifact.spec.ts +++ b/tests/chunk-artifact.spec.ts @@ -5,8 +5,10 @@ * be callable with a require that resolves the platform externals — the * exact shape the loader (src/client/chunk-loader.ts) depends on. Reads the * built lib/ output, so run `pnpm build` first (like manifest-consistency). + * A missing lib/ (fresh clone before the first build) skips the whole suite + * instead of crashing on ENOENT. */ -import { readFileSync } from 'node:fs' +import { existsSync, readFileSync } from 'node:fs' import { describe, expect, it } from 'vitest' // Browser globals first: chunk bodies probe `self`/`document` at evaluation // (xterm's UMD wrapper, CodeMirror's UA probe). @@ -17,7 +19,14 @@ const g = globalThis as Record const CHUNKS = ['terminal', 'editor', 'mermaid'] -describe('built chunk artifacts', () => { +/** All chunk artifacts present (tsdown emits the whole lib/ in one run). */ +const chunksBuilt = CHUNKS.every(name => existsSync(`lib/client-${name}.js`)) + +if (!chunksBuilt) { + console.warn('[chunk-artifact] lib/ chunk artifacts missing — run `pnpm build` first; skipping this suite') +} + +describe.skipIf(!chunksBuilt)('built chunk artifacts', () => { it('each chunk assigns its global registry slot when executed as a script', () => { g.window = g // classic-script globals // mermaid's core hooks window.addEventListener('load') at module scope diff --git a/tests/manifest-consistency.spec.ts b/tests/manifest-consistency.spec.ts index 00539e9..04ba007 100644 --- a/tests/manifest-consistency.spec.ts +++ b/tests/manifest-consistency.spec.ts @@ -11,7 +11,9 @@ * bundles must never be swapped. * * Reads the built lib/ output, so run `pnpm build` first (the registry - * install validates main/client.main existence the same way). + * install validates main/client.main existence the same way). A missing + * lib/ (fresh clone before the first build) skips the whole suite instead + * of crashing on ENOENT. */ import { describe, expect, it } from 'vitest' import { existsSync, readFileSync } from 'node:fs' @@ -20,6 +22,13 @@ import { fileURLToPath } from 'node:url' const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url))) +/** The build output is present (tsdown emits the whole lib/ in one run). */ +const libBuilt = existsSync(resolve(ROOT, 'lib/client.js')) + +if (!libBuilt) { + console.warn('[manifest-consistency] lib/ build output missing — run `pnpm build` first; skipping this suite') +} + /** The registry manifest face this spec touches (mirror of the registry's PluginManifest). */ interface PluginManifest { id: string @@ -72,7 +81,7 @@ function chunkSlot(file: string): string { return match[1]! } -describe('registry manifest consistency (dsh.plugin.json)', () => { +describe.skipIf(!libBuilt)('registry manifest consistency (dsh.plugin.json)', () => { it('id is a valid two-segment registry id (native form)', () => { expect(manifest.id).toMatch(ID_PATTERN) })