mrcrowl / vscode-hg

Integrated Mercurial source control for Visual Studio Code
MIT License
71 stars 37 forks source link

#95: Basic automated testing setup #106

Closed incidentist closed 4 years ago

incidentist commented 4 years ago

This sets up the extension to run automated tests. The process is finicky but it works, and is ready for contributors to add tests. A sample test is included in extension.test.ts that runs through hg.status and hg.addAll commands.

The entry point for the tests is runTest.ts.

Reference: https://code.visualstudio.com/api/working-with-extensions/testing-extension

How To Run

  1. Quit VS Code
  2. In a terminal, run npm run test.

This does the following:

  1. Downloads a sandbox version of VSCode
  2. Creates a temp directory
  3. Starts the VSCode sandbox version with the workspace set to the temp directory
  4. Runs the test suite, which runs hg init on the temp dir.

Finicky, you say? Well, yes. You need to quit VSCode for this to work or the npm command will complain, so if you want to edit code and run tests at the same time, edit the code in the VSCode Insiders Build.

The main limitation is that the tests can't be run from the launch bar. The launch.json config file is not expressive enough (AFAIK) to allow for a different temp directory to be used as the workspace each time. It bypasses runTest.ts completely and runs the test suite through an extension host that we don't have access to, so there is no way to run custom prep work (like creating a temp directory) before the VSCode sandbox is started.

mrcrowl commented 4 years ago

Awesome start!

hdpoliveira commented 4 years ago

One thing I noticed is that both git and the helloworld extension keep the tests in the src/test directory. I believe we should do the same