https://github.com/sourcegraph/extension-api-stubs
Stubs for the Sourcegraph extension API to unit-test Sourcegraph extensions
https://github.com/sourcegraph/extension-api-stubs
Last synced: 7 months ago
JSON representation
Stubs for the Sourcegraph extension API to unit-test Sourcegraph extensions
- Host: GitHub
- URL: https://github.com/sourcegraph/extension-api-stubs
- Owner: sourcegraph
- License: mit
- Created: 2019-04-24T08:19:42.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-07-02T00:46:53.000Z (7 months ago)
- Last Synced: 2025-07-03T14:18:03.324Z (7 months ago)
- Language: TypeScript
- Size: 599 KB
- Stars: 1
- Watchers: 58
- Forks: 3
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# @sourcegraph/extension-api-stubs
[](https://www.npmjs.com/package/@sourcegraph/extension-api-stubs)
[](https://www.npmjs.com/package/@sourcegraph/extension-api-stubs)
[](https://github.com/sourcegraph/extension-api-stubs/actions?query=branch%3Amaster)
[](https://codecov.io/gh/sourcegraph/extension-api-stubs)
[](https://github.com/prettier/prettier)
[](https://github.com/semantic-release/semantic-release)
## ⚠️ Deprecation notice
**Sourcegraph extensions have been deprecated with the September 2022 Sourcegraph
release. [Learn more](https://docs.sourcegraph.com/extensions/deprecation).**
The repo and the docs below are kept to support older Sourcegraph versions.
## Description
Stubs for the Sourcegraph extension API to unit-test Sourcegraph extensions
## Install
```
npm install @sourcegraph/extension-api-stubs
# or
yarn add @sourcegraph/extension-api-stubs
```
## Example
```ts
import mock from 'mock-require'
import { createStubSourcegraphAPI, createStubExtensionContext } from '@sourcegraph/extension-api-stubs'
const sourcegraph = createStubSourcegraphAPI()
// For modules importing Range/Location/Position/URI/etc
mock('sourcegraph', sourcegraph)
import * as sinon from 'sinon'
import { activate } from './extension'
describe('my extension', () => {
it('should register a hover provider', async () => {
const context = createStubExtensionContext()
await activate(context)
sinon.assert.calledOnce(sourcegraph.languages.registerHoverProvider)
const provider = sourcegraph.languages.registerHoverProvider.args[0][1]
const result = provider()
// More assertions ...
})
})
```
See the [Sinon documentation](https://sinonjs.org/) for more info on how to use the stubs.
## Build
```
yarn
yarn build
```
## Test
```
yarn test
```
## Release
Releases are done automatically in CI when commits are merged into master by analyzing [Conventional Commit Messages](https://conventionalcommits.org/).
After running `yarn`, commit messages will be linted automatically when committing though a git hook.
The git hook can be circumvented for fixup commits with [git's `fixup!` autosquash feature](https://fle.github.io/git-tip-keep-your-branch-clean-with-fixup-and-autosquash.html), or by passing `--no-verify` to `git commit`.
You may have to rebase a branch before merging to ensure it has a proper commit history, or squash merge with a manually edited commit message that conforms to the convention.