DSH Quality
进阶
3 分钟阅读

DSH 插件测试策略

DSH 插件测试策略 — 学习如何构建进阶 dsh 插件。

最后更新:2026-08-29

在隔离环境中测试插件

测试 dsh 插件最难的地方在于 ctx 是运行时对象。解决方案:mock ctx 并独立测试注册逻辑。

ts
import { describe, it, expect } from 'vitest';

describe('my-plugin', () => {
  it('registers hello command', () => {
    const mockCtx = { commands: { register: vi.fn() } };
    apply(mockCtx as any, {});
    expect(mockCtx.commands.register).toHaveBeenCalledWith('hello', expect.any(Object));
  });
});

这个模式让你不用启动 dsh 就能测试每个注册路径。