This commit is contained in:
Greg Van Liew 2023-11-01 08:00:48 -07:00
Родитель 86c869967b
Коммит eb2a70945f
3 изменённых файлов: 30 добавлений и 29 удалений

Просмотреть файл

@ -20,19 +20,19 @@ In the generated extension, you can use `npm run test` or `yarn test` to run the
- Downloads and unzips latest version of VS Code.
- Runs the [Mocha](https://mochajs.org) tests specified by the extension test runner script.
## Quick Setup: The Test CLI
## Quick Setup: The test CLI
The VS Code team publishes a command-line tool to run extensions tests. You can find and example in the [extensions sample repo](https://github.com/microsoft/vscode-extension-samples/tree/main/helloworld-test-cli-sample).
The VS Code team publishes a command-line tool to run extension tests. You can find an example in the [extensions sample repo](https://github.com/microsoft/vscode-extension-samples/tree/main/helloworld-test-cli-sample).
The test CLI provides quick setup, and also allows you to easily run and debug tests using the VS Code UI using the [Extension Test Runner](https://marketplace.visualstudio.com/items?itemName=ms-vscode.extension-test-runner). The CLI exclusively uses [Mocha](https://mochajs.org) under the hood.
The test CLI provides quick setup, and also allows you to easily run and debug tests of the VS Code UI using the [Extension Test Runner](https://marketplace.visualstudio.com/items?itemName=ms-vscode.extension-test-runner). The CLI exclusively uses [Mocha](https://mochajs.org) under the hood.
To get started, you'll want to first install the `@vscode/test-cli` module, as well as `@vscode/test-electron` module which enables tests to be run in VS Code Desktop:
To get started, you'll want to first install the `@vscode/test-cli` module, as well as `@vscode/test-electron` module that enables tests to be run in VS Code Desktop:
```
```bash
npm install --save-dev @vscode/test-cli @vscode/test-electron
```
After installing the modules, you'll get a `vscode-test` command line, which you can add to the `scripts` section in your package.json:
After installing the modules, you'll have the `vscode-test` command line, which you can add to the `scripts` section in your `package.json`:
```diff
{
@ -41,13 +41,15 @@ After installing the modules, you'll get a `vscode-test` command line, which you
+ "test": "vscode-test"
```
`vscode-test` will look for a [`.vscode-test.js/mjs/cjs`](https://github.com/microsoft/vscode-extension-samples/blob/main/helloworld-test-cli-sample/.vscode-test.mjs) file relative to the current working directory. This file provides configuration to test test runner, and you can find the entire definition [here](https://github.com/microsoft/vscode-test-cli/blob/main/src/config.cts). Common options include:
`vscode-test` looks for a [`.vscode-test.js/mjs/cjs`](https://github.com/microsoft/vscode-extension-samples/blob/main/helloworld-test-cli-sample/.vscode-test.mjs) file relative to the current working directory. This file provides the configuration for the test runner, and you can find the entire definition [here](https://github.com/microsoft/vscode-test-cli/blob/main/src/config.cts).
- **(required)** `files`: a pattern, list of patterns, or absolute paths containing the tests to run
- `version`: the version of VS Code to use for running tests (defaults to `stable`)
- `workspaceFolder`: the path to a workspace to open during tests
- `extensionDevelopmentPath`: the path to your extension folder (defaults to the directory the config file is placed in)
- `mocha`: an object containing additional [options](https://mochajs.org/api/mocha#Mocha) to pass to Mocha
Common options include:
- **(required)** `files` - A pattern, list of patterns, or absolute paths containing the tests to run.
- `version` - The version of VS Code to use for running tests (defaults to `stable`).
- `workspaceFolder` - The path to a workspace to open during tests.
- `extensionDevelopmentPath` - The path to your extension folder (defaults to the directory of the config file).
- `mocha` - An object containing additional [options](https://mochajs.org/api/mocha#Mocha) to pass to Mocha.
The configuration might be as simple as:
@ -65,23 +67,23 @@ module.exports = defineConfig({ files: 'out/test/**/*.test.js' });
const { defineConfig } = require('@vscode/test-cli');
module.exports = defineConfig([
{
label: 'unitTests',
files: 'out/test/**/*.test.js',
version: 'insiders',
workspaceFolder: './sampleWorkspace',
mocha: {
ui: 'tdd',
timeout: 20000,
},
},
// you can specify additional test configurations, too
{
label: 'unitTests',
files: 'out/test/**/*.test.js',
version: 'insiders',
workspaceFolder: './sampleWorkspace',
mocha: {
ui: 'tdd',
timeout: 20000,
},
},
// you can specify additional test configurations, too
]);
```
If you define multiple configurations by passing an array, they'll be run sequentially when you run `vscode-test`. You can filter by the `label` and run them individually using the `--label` flag, for example `vscode-test --label unitTests`. Run `vscode-test --help` for the complete set of command-line options.
### Test Scripts
### Test scripts
Once the CLI is set up, you can write and run your tests. Test scripts have access to the VS Code API, and are run under Mocha. Here's a sample ([src/test/suite/extension.test.ts](https://github.com/microsoft/vscode-extension-samples/blob/main/helloworld-test-sample/src/test/suite/extension.test.ts)):
@ -107,14 +109,13 @@ suite('Extension Test Suite', () => {
You can run this test with the `npm test` command, or by using the **Test: Run All Tests** command in VS Code after you install the [Extension Test Runner](https://marketplace.visualstudio.com/items?itemName=ms-vscode.extension-test-runner). You can also debug the test using **Test: Debug All Tests** command.
## Advanced Setup: Your Own Runner
## Advanced setup: Your own runner
You can find the configuration for this guide in the [helloworld-test-sample](https://github.com/microsoft/vscode-extension-samples/tree/main/helloworld-test-sample). The rest of this document explains these files in the context of the sample:
- The **test script** ([`src/test/runTest.ts`](https://github.com/microsoft/vscode-extension-samples/blob/main/helloworld-test-sample/src/test/runTest.ts))
- The **test runner script** ([`src/test/suite/index.ts`](https://github.com/microsoft/vscode-extension-samples/blob/main/helloworld-test-sample/src/test/suite/index.ts))
VS Code provides two CLI parameters for running extension tests, `--extensionDevelopmentPath` and `--extensionTestsPath`.
For example:

Просмотреть файл

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:129156814b4aaf72be8064a753bb6a1c3ed7bebe62f0f1273f85bfba0abbe544
size 27250
oid sha256:b266265d29f7c73a7388c5a71af9a2307055001152e80737197bbdb334cd66a7
size 36598

Просмотреть файл

@ -20,7 +20,7 @@ Welcome to the October 2023 release of Visual Studio Code. There are many update
* **[Python improvements](#python)** - Better run code in terminal, easier virtual environment creation.
* **[FastAPI tutorial](#fastapi-tutorial)** - Learn about developing Python FastAPI apps with VS Code.
* **[Gradle for Java](#gradle-for-java)** - Improved support for Java Gradle projects.
* **[Preview: GitHub Copilot](#github-copilot)** - Streaming inline chat, chat agents, terminal support.
* **[Preview: GitHub Copilot](#github-copilot)** - Chat "agents", generate commit messages, terminal support.
>If you'd like to read these release notes online, go to [Updates](https://code.visualstudio.com/updates) on [code.visualstudio.com](https://code.visualstudio.com).