Skip to content

Running tests

ageorgou edited this page May 6, 2021 · 2 revisions

We use mocha to write and run tests. Tests are located under src/test/ (individual test files in src/test/suite). When they run, they will first try to find the latest version of VS Code, and download it if required.

Tests can be run from the command line or from within VS Code itself.

Command line

From the root directory, run npm run test. Under the hood, this will run the command node ./out/test/runTest.js (defined in package.json)

Note: When running from the command line, the version of VS Code used in testing cannot already be running (source 1, source 2). This situation will give an error like:

Running extension tests from the command line is currently only supported if no other instance of Code is running. To work around this, you can:

  • use a version of VS Code that is not the latest stable (as the tests will download/use the latter); this can also be the nightly build (VS Code Insiders)
  • exit VS Code before running the tests
  • run the tests through the GUI (see below)

GUI

An advantage of this is that you can also run the tests in debug mode (how?).

You will first need to create a launch configuration to do this.

  1. Open the .vscode/launch.json file (you can use the command "Open launch.json" from the Palette)
  2. Add this configuration in the configurations key:
       {
            "name": "Run tests",
            "request": "launch",
            "runtimeArgs": [
                "run-script",
                "test"
            ],
            "runtimeExecutable": "npm",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "type": "pwa-node"
        }

The above adds the option to replicate the npm run test command from within the GUI.

When that is done, you can run the tests:

  1. Selecting the Run/Debug icon on the sidebar on the left, to access these options.
  2. From the dropdown "RUN AND DEBUG" menu, choose the "Run tests" configuration (or whatever you named it above).
  3. Click the run icon next to the name.
Clone this wiki locally