fix(test): add missing devDeps + sourcemap transform + jsdom directives

WorkBuddy review found 38 of 131 spec files failed at collection time
(0 tests executed) — the '1015 passed' was a false green because vitest
only counts 'Tests failed', not 'Test Files failed'.

Root cause: dsh-client-ui-primitives@0.2.0-rc.2 declares dependencies:null
but statically imports 23 external root packages. Our project declared
only 18. Under pnpm strict layout, the missing 5 (dsh-client-store,
dsh-util-code-language, dsh-util-workspace-path, diff, simple-icons)
were unresolvable when Vite inlined the primitives package.

Fixes:
- Add 7 missing devDeps: dsh-client-store@0.2.0-rc.2,
  dsh-util-code-language@0.2.0-rc.2, dsh-util-workspace-path@0.2.0-rc.2,
  diff@9.0.0, simple-icons@16.35.0, zustand@5.0.15, immer@11.1.21
- vitest.config.ts: add transform plugin to strip sourceMappingURL
  comments from dsh-client-ui-primitives (upstream ships lib/index.js
  with trailing sourceMappingURL but package.json files excludes .map)
- 5 spec files: add @vitest-environment jsdom directive (they import
  dsh-client-ui-primitives which calls window.addEventListener at module
  load; node environment lacks window)
- Remove empty .map file hack from node_modules (ineffective + .gitignore
  blocks it from version control)

Result: Test Files 131 passed (131), Tests 1367 passed | 9 skipped,
EXIT=0.

Verified: simple-icons 25 named exports all present.
Typecheck + build pass.
This commit is contained in:
figmar committed 2026-10-11 19:33:01 +08:00
1 parent f4c44d13d6
commit a6dd8aa42a
9 files changed
+117 -1

No files matched your search

+14
View File
@@ -12,7 +12,21 @@
*/
import { defineConfig } from 'vitest/config'
// 上游 dsh-client-ui-primitives 的 lib 带 sourceMappingURL 注释但未发布 map
// 文件(package.json 的 files 不含 .map)→ Vite 读 map 报 ENOENT。
// 这里在 transform 阶段剥掉该注释;不要手改 node_modules(pnpm install 即失效)。
const stripMissingSourcemapRefs = {
name: 'strip-missing-sourcemap-refs',
enforce: 'pre' as const,
transform(code: string, id: string) {
if (!id.includes('dsh-client-ui-primitives')) return
if (!code.includes('sourceMappingURL')) return
return { code: code.replace(/\/\/\/?\s*sourceMappingURL=.*$/gm, ''), map: null }
},
}
export default defineConfig({
plugins: [stripMissingSourcemapRefs],
test: {
// Bridge Node's `localStorage` accessor to jsdom's store (see the file).
setupFiles: ['tests/setup.ts'],