Search code examples
visual-studio-codeintegration-testingvscode-extensions

How do I run integration tests for a vscode extension that depends on other extensions


The vscode API documentation includes a page on how to test extensions. This works well when you have a single extension with no dependencies. However, in our case, we extensionDependencies since our extension depends on hbenl.vscode-test-explorer.

On our CI server, we have a problem that we cannot run the tests until this dependency is installed, but there is no API exposed by vscode's test API to install extensions.

We could download our own copy of vscode and use the --install-extension command to install this dependency, but that complicates things since now we are managing the download that the API used to manage.

There are two reasonable possibilities that I would like to explore:

  1. How can I disable the extensionDependencies when activating my extension?
  2. How can I download the dependency as part of the vscode-test run?

Solution

  • Somehow, I missed this in the documentation. Custom setup with vscode-test.

    The code is available at the link, so I won't copy all of it. Here's the most relevant part:

        const vscodeExecutablePath = await downloadAndUnzipVSCode('stable');
        const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath);
    
        // Use cp.spawn / cp.exec for custom setup
        cp.spawnSync(cliPath, ['--install-extension', '<EXTENSION-ID-OR-PATH-TO-VSIX>'], {
          encoding: 'utf-8',
          stdio: 'inherit'
        });