Skip to content

Commit

Permalink
update documenation
Browse files Browse the repository at this point in the history
  • Loading branch information
jpogran committed Jan 19, 2022
1 parent bb4ca7e commit 0916ea1
Showing 1 changed file with 78 additions and 17 deletions.
95 changes: 78 additions & 17 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,93 @@
# Building
# Development

We are an open source project on GitHub and would enjoy your contributions! Please [open a new issue](https://github.com/hashicorp/terraform-vscode-extension/issues) before working on a PR that requires significant effort. This will allow us to make sure the work is in line with the project's goals.

## Building

The extension makes use of the [VSCode Language Server](https://github.com/Microsoft/vscode-languageserver-node) client package to integrate with [terraform-ls](https://github.com/hashicorp/terraform-ls) for [language features](https://code.visualstudio.com/api/language-extensions/programmatic-language-features). The directions below cover how to build and package the extension; please see the `terraform-ls` documentation for how to build the language server executable.

Requirements:
### Requirements:

- Node
- npm
- VSCode
- VSCode >= 1.61
- Node >= 16.13.2
- npm >= 8.x

After cloning the repo, run `npm i` to install dependencies. There's an included build task to compile the TypeScript files to JavaScript; you can run it directly with `npm run compile`.
### Getting the code

In order to use an independently built or installed version of `terraform-ls`, you will need to set `terraform.languageServer.pathToBinary` to the correct executable path.
```
git clone https://github.com/hashicorp/vscode-terraform
```

The extension can be run in a development mode (useful for testing syntax highlighting changes, for example) via the debug task called `Launch Client`. This will open a new window with the extension loaded, and from there you can open any files or folders you want to check against. This extension development window can also be used to run commands, and use the language server installer.
### Dependencies:

To package your local development copy for testing, use the [vsce](https://www.npmjs.com/package/vsce) tool with `vcse package`.
After cloning the repo, run `npm install` to install dependencies. There's an included build task to compile the TypeScript files to JavaScript; you can run it directly with `npm run compile`.

# Development
```
> npm install
> npm run compile
```

We are an open source project on GitHub and would enjoy your contributions! Please [open a new issue](https://github.com/hashicorp/terraform-vscode-extension/issues) before working on a PR that requires significant effort. This will allow us to make sure the work is in line with the project's goals.
## Running the Extension

The extension can be run in a development mode via the debug task called `Launch Client`. This will open a new VS Code window with the extension loaded, and from there you can open any files or folders you want to check against. This extension development window can also be used to run commands or any other feature the extension provides.

## Tests

Automated `unit` and `integration` tests can be written using [mocha](https://mochajs.org) and live inside `./src/test` with file pattern `*.test.ts`.

>It is *required* that `terraform` is available on `$PATH` to run the tests.
To run the `unit tests` from the command-line run:

```bash
> `npm test:unit`
```

To run the `integration tests` from the command-line without any configuration, close any open VSCode windows and run `npm test`. By default, `npm test` will test against VS Code Stable. If you want to test against a different VS Code version, or if you want to have VS Code remain open, use an environment variable to indicate which version of VS Code to test against:

```bash
# VS Code Stable is open, use Insiders:
> VSCODE_VERSION='insiders' npm test

# VS Code Insiders is open, use Stable:
> VSCODE_VERSION='stable' npm test

# Test against VS Code v1.55.8:
> VSCODE_VERSION='1.55.8' npm test
```

To run the `integration` tests in PowerShell, set the environment variable accordingly:

```powershell
# VS Code Stable is open, use Insiders:
> $env:VSCODE_VERSION ='insiders'
> npm test
```

The tests can also be run within VSCode itself, using the launch task `Run Extension Tests`. This will open a new VS Code window, run the test suite, and exit with the test results.

### Acceptance Tests

End to end acceptance tests with the extension running against the language server are a work in progress. An example can be seen in [`./src/test/integration/symbols.test.ts`](src/test/integration/symbols.test.ts).

Unfortunately automated user input does not appear to be possible (keypresses, cursor clicks) at the moment, but some integration testing can be performed by using the vscode API to open/edit files, and triggering events/commands such as language server requests and verifying the responses.

The `terraform init` command runs automatically when tests are executed.

### Test Fixture Data

Sample files for tests should be added to the [`./testFixture`](testFixture/) folder, this is the folder vscode will open during tests. Starting from this folder will prevent the language server from walking other folders that typically exist such as `node_modules`.

## Packaging

# Testing
To package the extension into a `platform specific VSIX` ready for testing run the following command:

Automated tests can be written using [mocha](https://mochajs.org) and live inside `./src` with file pattern `*.test.ts`. To run the tests from the command-line with `npm t` you will need to have closed any open VSCode windows. The tests can also be run within VSCode itself, using the debug task `Run Extension Tests`. It is required that `terraform` is available on `$PATH` for integration tests of the language server.
```
npm run package -- --target=win32-x64
```

## Integration Tests
It is possible to write integration tests with the extension running against the language server. An example can be seen in [`./src/test/symbols.test.ts`](src/test/symbols.test.ts). Unfortunately automated user input does not appear to be possible (keypresses, cursor clicks), but some integration testing can be performed by using the vscode API to open/edit files, and triggering events/commands such as language server requests and verifying the responses.
Replace `target` with the platform/architecture combination that is on the supported matrix list.

Any of the [built in commands](https://code.visualstudio.com/api/references/commands) along with any custom commands the extension has defined can be triggered. Where needed, [expose items to the public API](https://github.com/hashicorp/vscode-terraform/blob/70bfcf060e3e2d75cfa67a453cd4c9e1cec9a1d4/src/extension.ts#L87) of the extension for [inspection](https://github.com/hashicorp/vscode-terraform/blob/70bfcf060e3e2d75cfa67a453cd4c9e1cec9a1d4/src/test/helper.ts#L33) during tests. Helpers, such as the `open` helper should be added to [`./src/test/helper.ts`](src/test/helper.ts).
This will run several chained commands which will download the specified version of terraform-ls, minify the extension using esbuild, and package the extension using vsce into a VSIX.

Sample files for tests should be added to the [`./testFixture`](testFixture/) folder, this is the folder vscode will open with during tests, the running of `terraform init` has been automated. Starting from this folder will prevent the language server from walking this projects other folders that typically exist such as `node_modules`, however `process.cwd()` is still be the project root.
> You can run `npm run package` without paramaters, but this will not produce a platform specific extension.

0 comments on commit 0916ea1

Please sign in to comment.