5
votes

When using the official generator to start a VSCode extension, it automatically generates the extension.test.ts and index.ts files. index.ts just contains the setup for the test runner to use for extension tests, and it is Mocha based. The Mocha test runner itself can be seen here: https://github.com/Microsoft/vscode-extension-vscode/blob/master/lib/testrunner.js.

I've been scouring around trying to find any official Jest based one. Does anyone know of one?

1
Did you find something or build it yourself? - fabianmoronzirfas
I found this project that had working code: github.com/rozzzly/vscode-prompt-debug/tree/master/test. - user1795832

1 Answers

0
votes

There is no official one, you have to create it yourself.

Igor Soloydenko wrote a guide on how to do that last year (2019):

https://medium.com/@soloydenko/end-to-end-testing-vs-code-extensions-via-jest-828e5edfeb75

Psuedocode:

const jestTestRunnerForVSCodeE2E: ITestRunner = {
  run(testsRoot: string, clb: (error: Error, failures?: number) => void): void {
    try {
      const result = runJestTests(configuration);
      if (result.executionError) {
        clb(result.executionError);
      } else {
        clb(undefined, result.numberOfFailedTests);
      }
    } catch (e) {
      clb(e);
    }
  }
};

module.exports = jestTestRunnerForVSCodeE2E;

And of course there is the link @user1795832 provided: https://github.com/rozzzly/vscode-prompt-debug/tree/master/test

The code in that link was last updated May 2018 so not sure if it still works.