- 新 src/client/builtins/ 目录:tabs.tsx(6 个 tab descriptor + TERMINAL_LIMIT/uiTerminalCount,terminal 配额知识离开 state.ts)、 viewers.tsx(8 个 viewer descriptor)、index.ts(registerBuiltins 聚合 注册 + 幂等 disposer);删除旧 builtins.tsx - icons.tsx:删除零调用者的 tabTypeIcon 及多余 import(图标已归 descriptor.icon,映射随 tab 类型一起注册化) - OrphanedTab:内联 style → sidebar.module.css 新增 .orphanedType 类 - 新增 tests/builtins.spec.ts(6 tab + 8 viewer 注册断言、code catch-all、 binary-download NUL detect、office 优先级、disposer 幂等) - 新增 tests/orphaned-tab.spec.tsx(sanitize 保留未注册类型 tab、 OrphanedTab 占位渲染);tests/browser-globals.ts 供拉入 xterm/ CodeMirror 的 spec 首个 import(模块求值期需要 self/document/navigator) - service.spec 补 openDiffTab 与 diff dedupeKey 一致性用例
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
/**
|
|
* Browser globals for specs that pull browser-bound modules. Import this
|
|
* FIRST in a spec file: unlike statements after imports (which vitest
|
|
* hoists above the module body), an import statement evaluates in order,
|
|
* so this runs before any later import's module graph (xterm's UMD wrapper
|
|
* checks `self` and its color defaults probe `document` at evaluation time;
|
|
* window/localStorage are only touched at runtime by the store).
|
|
*/
|
|
const g = globalThis as Record<string, unknown>
|
|
|
|
if (g.self === undefined) g.self = globalThis
|
|
|
|
const elementStub = (): Record<string, unknown> => ({
|
|
style: {},
|
|
classList: { add: () => {}, remove: () => {}, contains: () => false },
|
|
setAttribute: () => {},
|
|
getAttribute: () => null,
|
|
appendChild: () => {},
|
|
addEventListener: () => {},
|
|
removeEventListener: () => {},
|
|
getBoundingClientRect: () => ({ left: 0, top: 0, width: 0, height: 0 }),
|
|
// xterm's color palette probe measures a canvas context at module load.
|
|
getContext: () => null,
|
|
})
|
|
|
|
if (g.document === undefined) {
|
|
g.document = {
|
|
createElement: () => elementStub(),
|
|
createDocumentFragment: () => elementStub(),
|
|
addEventListener: () => {},
|
|
removeEventListener: () => {},
|
|
defaultView: globalThis,
|
|
body: elementStub(),
|
|
// CodeMirror's view module probes the UA and injects styles at load.
|
|
documentElement: elementStub(),
|
|
head: elementStub(),
|
|
styleSheets: [],
|
|
}
|
|
}
|
|
|
|
if (g.navigator === undefined) {
|
|
g.navigator = { userAgent: 'node', platform: 'node', vendor: '', maxTouchPoints: 0 }
|
|
}
|
|
|
|
if (g.window === undefined) {
|
|
g.window = {
|
|
clearTimeout: () => {},
|
|
setTimeout: (_fn: () => void) => 0,
|
|
innerWidth: 1024,
|
|
getComputedStyle: () => ({ getPropertyValue: () => '' }),
|
|
}
|
|
}
|
|
|
|
if (g.localStorage === undefined) {
|
|
g.localStorage = {
|
|
getItem: () => null,
|
|
setItem: () => {},
|
|
}
|
|
}
|