1

I am writing a test suite for my VS Code extension using vscode-extension-tester, and my tests need to involve the opening of a workspace file. I need the workspace file to be opened as soon as the browser is launched, in order for my subsequent tests to pass.

I am able to open the workspace file as a separate test; however, I was wondering if there's any setting that allows the workspace to be opened before any test is launched. Is there a way to do this with vscode-extension-tester?

notexactly
  • 918
  • 1
  • 5
  • 21

1 Answers1

0

The way I handle this is through my launch configuration (launch.json).

Using an extensionHost type launch configuration you can pass a workspace file. This means that the code instance will open with the given workspace active whenever you execute it.

For example:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run Extension",
            "type": "extensionHost",
            "request": "launch",
            "args": [
                "${workspaceFolder}/src/test/workspace/workspace.code-workspace",
                "--extensionDevelopmentPath=${workspaceFolder}"
            ],
            "outFiles": [
                "${workspaceFolder}/dist/**/*.js"
            ],
            "preLaunchTask": "${defaultBuildTask}"
        },
        {
            "name": "Extension Tests",
            "type": "extensionHost",
            "request": "launch",
            "args": [
                "${workspaceFolder}/src/test/workspace/workspace.code-workspace",
                "--extensionDevelopmentPath=${workspaceFolder}",
                "--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
            ],
            "outFiles": [
                "${workspaceFolder}/out/**/*.js",
                "${workspaceFolder}/dist/**/*.js"
            ],
            "preLaunchTask": "tasks: watch-tests"
        }
    ]
}

Note the path to workspace.code-workspace that is specified as an arg to both of these launch configs.

You will likely already have launch configs like this for running and testing your extension if you used Yo Code to generate your extension at the start of development.

So in summary:

  1. Create your workspace
  2. Store the workspace file accordingly (for me it made sense to be within ./src/test)
  3. Configure extensionHost type launch configs with a path to the workspace file given as an arg in the args array.