vscode-test/README.md

148 строки
4.3 KiB
Markdown
Исходник Постоянная ссылка Обычный вид История

2021-01-26 00:22:40 +03:00
# vscode-test
2021-01-26 00:24:04 +03:00
![Test Status Badge](https://github.com/microsoft/vscode-test/workflows/Tests/badge.svg)
2019-03-14 21:33:54 +03:00
This module helps you test VS Code extensions. Note that new extensions may want to use the [VS Code Test CLI](https://github.com/microsoft/vscode-test-cli/blob/main/README.md), which leverages this module, for a richer editing and execution experience.
2019-03-14 21:33:54 +03:00
Supported:
- Node >= 16.x
2019-05-24 11:41:00 +03:00
- Windows >= Windows Server 2012+ / Win10+ (anything with Powershell >= 5.0)
- macOS
- Linux
2019-03-14 21:33:54 +03:00
## Usage
See [./sample](./sample) for a runnable sample, with [Azure DevOps Pipelines](https://github.com/microsoft/vscode-test/blob/main/sample/azure-pipelines.yml) and [Github ACtions](https://github.com/microsoft/vscode-test/blob/main/sample/.travis.yml) configuration.
2019-03-14 21:44:45 +03:00
2019-03-14 21:33:54 +03:00
```ts
import { runTests, runVSCodeCommand, downloadAndUnzipVSCode } from '@vscode/test-electron';
2021-07-15 22:11:14 +03:00
2019-03-14 21:33:54 +03:00
async function go() {
2019-09-25 21:37:26 +03:00
try {
2023-02-28 02:17:27 +03:00
const extensionDevelopmentPath = path.resolve(__dirname, '../../../');
const extensionTestsPath = path.resolve(__dirname, './suite');
2019-09-25 21:37:26 +03:00
/**
* Basic usage
*/
await runTests({
extensionDevelopmentPath,
2023-02-28 02:17:27 +03:00
extensionTestsPath,
});
2019-09-25 21:37:26 +03:00
2023-02-28 02:17:27 +03:00
const extensionTestsPath2 = path.resolve(__dirname, './suite2');
const testWorkspace = path.resolve(__dirname, '../../../test-fixtures/fixture1');
2019-09-25 21:37:26 +03:00
/**
* Running another test suite on a specific workspace
*/
await runTests({
extensionDevelopmentPath,
extensionTestsPath: extensionTestsPath2,
2023-02-28 02:17:27 +03:00
launchArgs: [testWorkspace],
});
2019-09-25 21:37:26 +03:00
/**
* Use 1.36.1 release for testing
*/
await runTests({
version: '1.36.1',
extensionDevelopmentPath,
extensionTestsPath,
2023-02-28 02:17:27 +03:00
launchArgs: [testWorkspace],
});
2019-09-25 21:37:26 +03:00
/**
* Use Insiders release for testing
*/
await runTests({
version: 'insiders',
extensionDevelopmentPath,
extensionTestsPath,
2023-02-28 02:17:27 +03:00
launchArgs: [testWorkspace],
});
2019-09-25 21:37:26 +03:00
/**
* Noop, since 1.36.1 already downloaded to .vscode-test/vscode-1.36.1
*/
2023-02-28 02:17:27 +03:00
await downloadAndUnzipVSCode('1.36.1');
2019-09-25 21:37:26 +03:00
/**
* Manually download VS Code 1.35.0 release for testing.
*/
2023-02-28 02:17:27 +03:00
const vscodeExecutablePath = await downloadAndUnzipVSCode('1.35.0');
2019-09-25 21:37:26 +03:00
await runTests({
vscodeExecutablePath,
extensionDevelopmentPath,
extensionTestsPath,
2023-02-28 02:17:27 +03:00
launchArgs: [testWorkspace],
});
2019-09-25 21:37:26 +03:00
/**
* Install Python extension
*/
await runVSCodeCommand(['--install-extension', 'ms-python.python'], { version: '1.35.0' });
2019-09-25 21:37:26 +03:00
/**
* - Add additional launch flags for VS Code
* - Pass custom environment variables to test runner
*/
await runTests({
vscodeExecutablePath,
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [
testWorkspace,
2021-03-09 19:08:30 +03:00
// This disables all extensions except the one being tested
2023-02-28 02:17:27 +03:00
'--disable-extensions',
2019-09-25 21:37:26 +03:00
],
// Custom environment variables for extension test script
2023-02-28 02:17:27 +03:00
extensionTestsEnv: { foo: 'bar' },
});
2019-12-12 00:19:31 +03:00
/**
* Use win64 instead of win32 for testing Windows
*/
if (process.platform === 'win32') {
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
version: '1.40.0',
2023-02-28 02:17:27 +03:00
platform: 'win32-x64-archive',
2019-12-12 00:19:31 +03:00
});
}
2019-09-25 21:37:26 +03:00
} catch (err) {
2023-02-28 02:17:27 +03:00
console.error('Failed to run tests');
process.exit(1);
2019-09-25 21:37:26 +03:00
}
2019-03-14 21:33:54 +03:00
}
2023-02-28 02:17:27 +03:00
go();
2019-03-14 21:33:54 +03:00
```
2020-04-13 21:46:53 +03:00
## Development
- `yarn install`
- Make necessary changes in [`lib`](./lib)
- `yarn compile` (or `yarn watch`)
- In [`sample`](./sample), run `yarn install`, `yarn compile` and `yarn test` to make sure integration test can run successfully
2019-03-14 21:33:54 +03:00
## License
[MIT](LICENSE)
## Contributing
2019-06-27 15:38:45 +03:00
This project welcomes contributions and suggestions. Most contributions require you to agree to a
2019-03-14 21:33:54 +03:00
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.