mock-vscode
v1.0.0
Published
A comprehensive mock of the VS Code API for testing
Downloads
54
Maintainers
Readme
mock-vscode
TypeScript mock of the Visual Studio Code extension API for unit tests and development.
This repository provides lightweight mock implementations of many top-level vscode namespaces (commands, window, workspace, languages, extensions, env, debug, tasks, notebooks, lm, chat, scm, tests, authentication, comments, l10n, etc.) together with test affordances and Jest tests.
Quick start
Install dependencies:
npm installRun the test suite:
npm testBuild (type check + bundle):
npm run buildFormat the code (Prettier):
npm run formatRun ESLint autofix:
npm run lint:fixGenerate documentation (TypeDoc):
npm run docsUsage
Import the mocks from src in tests or test helpers. Example:
import { languages, createMockTextDocument } from 'mock-vscode';
const doc = createMockTextDocument('const x = 1;', { languageId: 'javascript' });
const collection = languages.createDiagnosticCollection('tests');Note: the library exposes test affordances (methods prefixed with _) such as _reset(), _get*() and _createMock*() to make unit testing predictable.
Contributing
- Use 4-space indentation (Prettier is configured).
- Add tests under
src/__tests__and update TypeDoc comments when adding APIs. - Run the formatter and tests before submitting PRs.
License
MIT
