新增 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 侧的对称改动。
20 lines
708 B
TypeScript
20 lines
708 B
TypeScript
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);
|
||
});
|
||
});
|