yggdrasil/libs/shared/src/index.test.ts
xfy 9bc8b5c2ee refactor(libs): 抽取 @yggdrasil/shared 消除跨 IIFE 库的类型/常量重复
新增 libs/shared 内部包,作为跨 IIFE 库的单一真相源:
- ThemeName 类型(原 codemirror/themes.ts + xterm/themes.ts 各一份)
- THEME_CHANGE_EVENT 常量(原 yggdrasil-core 导出 + codemirror/xterm
  各硬编码同名 string literal,靠注释维系一致)
- prefersReducedMotion 函数(原 lightbox + yggdrasil-core 各一份)

codemirror-editor / xterm-terminal / lightbox / yggdrasil-core 四个库
改为 workspace 依赖 @yggdrasil/shared,Vite 构建时 inline 进各自 IIFE,
不破坏 IIFE 隔离。消除「改一处忘改另一处导致静默失效」的风险。

附:image_reader_limits 已在上一提交共享;本提交是 libs 侧的对称改动。
2026-07-14 15:39:41 +08:00

20 lines
708 B
TypeScript
Raw 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.

import { describe, expect, it } from 'vitest';
import { prefersReducedMotion, THEME_CHANGE_EVENT, type ThemeName } from './index';
describe('@yggdrasil/shared', () => {
it('THEME_CHANGE_EVENT 是固定字符串', () => {
expect(THEME_CHANGE_EVENT).toBe('yggdrasil:theme-change');
});
it('prefersReducedMotion 在无 matchMedia 时返回 false', () => {
// happy-dom 提供了 matchMedia这里只验证函数可调用且返回 boolean
const result = prefersReducedMotion();
expect(typeof result).toBe('boolean');
});
it('ThemeName 类型仅接受 light/dark编译期约束', () => {
const t: ThemeName = 'light';
expect(['light', 'dark']).toContain(t);
});
});