Intermediate
Testing Strategies for DSH Plugins
Testing Strategies for DSH Plugins — Learn how to build intermediate dsh plugins.
Test your plugin in isolation
The hardest part about testing dsh plugins is that ctx is a runtime object. The solution: mock ctx and test your registration logic independently.
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));
});
});This pattern lets you test every registration path without starting dsh.