New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support extension testing #733

sqs opened this Issue Sep 13, 2018 · 1 comment


None yet
3 participants
Copy link

sqs commented Sep 13, 2018

Currently it is not possible to run automated tests of any JavaScript module that imports sourcegraph. This means it is not possible to write tests for Sourcegraph extensions (unless you very carefully separate your code and only import certain modules in your tests).

You get an error like the following if you try it:

$ npm run test

> sourcegraph-basic-code-intel@0.0.0-development test /home/sqs/src/
> TS_NODE_COMPILER_OPTIONS='{"module":"commonjs"}' mocha --require ts-node/register --require source-map-support/register --opts mocha.opts

module.exports = global.require('sourcegraph')
TypeError: global.require is not a function
    at Object.<anonymous> (/home/sqs/src/
    at Module._compile (module.js:624:30)

This is because we inject the sourcegraph module at runtime in the client, and there is currently no facility for doing so when you run the code via node, mocha, etc.

We need to add support for this.

@chrismwendt chrismwendt transferred this issue from sourcegraph/sourcegraph-extension-api Nov 5, 2018


This comment has been minimized.

Copy link

lguychard commented Dec 4, 2018

I came up with a workaround for this when writing tests for sourcegraph-string-references using sinon and intercept-require.

This was inspired by sinon-chrome, which I've used in a similar fashion in the past to perform e2e blackbox testing of the bundled background script of a chrome extension.

Maybe this could be a good starting point.

@sqs sqs assigned lguychard and unassigned chrismwendt Dec 5, 2018

@lguychard lguychard added this to the Backlog milestone Feb 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment