2019-05-24 03:00:27 +03:00
< p >
< h1 align = "center" > vscode-test< / h1 >
< / p >
< p align = "center" >
2019-05-30 04:04:15 +03:00
< a href = "https://dev.azure.com/vscode/vscode-test/_build?definitionId=15" >
< img src = "https://img.shields.io/azure-devops/build/vscode/350ef5c4-15fc-411a-9a5e-0622da4da69c/15.svg?label=Azure%20DevOps&logo=Azure%20Devops&style=flat-square" >
2019-05-24 03:00:27 +03:00
< / a >
2019-06-28 03:03:52 +03:00
< a href = "https://travis-ci.org/microsoft/vscode-test" >
< img src = "https://img.shields.io/travis/microsoft/vscode-test.svg?label=Travis&logo=Travis&style=flat-square" >
< / a >
2019-05-24 03:00:27 +03:00
< / p >
2019-03-14 21:33:54 +03:00
2019-03-20 08:20:11 +03:00
This module helps you test VS Code extensions.
2019-03-14 21:33:54 +03:00
2019-03-21 22:22:58 +03:00
Supported:
2019-05-23 21:17:22 +03:00
- Node >= 8.x
2019-05-24 11:41:00 +03:00
- Windows >= Windows Server 2012+ / Win10+ (anything with Powershell >= 5.0)
2019-03-21 22:22:58 +03:00
- macOS
- Linux
2019-03-14 21:33:54 +03:00
## Usage
2019-08-02 01:52:03 +03:00
See [./sample ](./sample ) for a runnable sample, with [Azure DevOps Pipelines ](https://github.com/microsoft/vscode-test/blob/master/sample/azure-pipelines.yml ) and [Travis CI ](https://github.com/microsoft/vscode-test/blob/master/.travis.yml ) configuration.
2019-03-14 21:44:45 +03:00
2019-03-14 21:33:54 +03:00
```ts
2019-07-17 17:19:35 +03:00
import * as path from 'path'
import { runTests, downloadAndUnzipVSCode } from 'vscode-test'
2019-03-14 21:33:54 +03:00
async function go() {
2019-07-10 13:06:36 +03:00
const extensionDevelopmentPath = path.resolve(__dirname, '../../')
const extensionTestsPath = path.resolve(__dirname, './suite')
2019-03-14 21:33:54 +03:00
const testWorkspace = path.resolve(__dirname, '../../test-fixtures/fixture1')
2019-03-14 21:44:45 +03:00
/**
* Basic usage
*/
2019-03-14 21:33:54 +03:00
await runTests({
2019-07-10 13:06:36 +03:00
extensionDevelopmentPath,
extensionTestsPath,
2019-07-11 20:13:24 +03:00
launchArgs: [testWorkspace]
2019-03-14 21:33:54 +03:00
})
2019-03-14 21:44:45 +03:00
2019-07-10 13:06:36 +03:00
const extensionTestsPath2 = path.resolve(__dirname, './suite2')
2019-03-20 08:20:11 +03:00
const testWorkspace2 = path.resolve(__dirname, '../../test-fixtures/fixture2')
/**
* Running a second test suite
*/
await runTests({
2019-07-10 13:06:36 +03:00
extensionDevelopmentPath,
extensionTestsPath: extensionTestsPath2,
launchArgs: [testWorkspace2]
2019-03-20 08:20:11 +03:00
})
/**
2019-08-02 02:41:13 +03:00
* Use 1.36.1 release for testing
2019-03-20 08:20:11 +03:00
*/
await runTests({
2019-08-02 02:41:13 +03:00
version: '1.36.1',
2019-07-10 13:06:36 +03:00
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace]
2019-03-20 08:20:11 +03:00
})
2019-04-17 23:32:38 +03:00
/**
* Use Insiders release for testing
*/
await runTests({
version: 'insiders',
2019-07-10 13:06:36 +03:00
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace]
2019-04-17 23:32:38 +03:00
})
2019-03-20 08:20:11 +03:00
/**
2019-08-02 02:41:13 +03:00
* Manually download VS Code 1.36.1 release for testing.
* Noop, since 1.36.1 already downloaded by the previous command to '.vscode-test/vscode-1.36.1'.
2019-03-20 08:20:11 +03:00
*/
2019-08-02 02:41:13 +03:00
await downloadAndUnzipVSCode('1.36.1')
2019-04-13 22:36:15 +03:00
/**
2019-08-02 02:41:13 +03:00
* Manually download VS Code 1.35.0 release and run tests on it.
2019-04-13 22:36:15 +03:00
*/
2019-08-02 02:41:13 +03:00
const vscodeExecutablePath = await downloadAndUnzipVSCode('1.35.0')
2019-04-13 22:36:15 +03:00
await runTests({
vscodeExecutablePath,
2019-07-10 13:06:36 +03:00
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace]
2019-04-13 22:36:15 +03:00
})
2019-08-03 00:24:38 +03:00
/**
* Install Python extension
*/
const cliPath = resolveCliPathFromExecutablePath(vscodeExecutablePath);
cp.spawnSync(cliPath, ['--install-extension', 'ms-python.python'], {
encoding: 'utf-8',
stdio: 'inherit'
});
2019-04-13 22:36:15 +03:00
/**
2019-07-10 13:06:36 +03:00
* - Add additional launch flags for VS Code.
* - Pass custom environment variables to test runner.
2019-04-13 22:36:15 +03:00
*/
await runTests({
vscodeExecutablePath,
2019-07-10 13:06:36 +03:00
extensionDevelopmentPath,
extensionTestsPath,
2019-04-13 22:36:15 +03:00
launchArgs: [
testWorkspace,
2019-07-10 13:06:36 +03:00
// This disables all extensions except the one being testing.
'--disable-extensions'
],
// Custom environment variables for extension test script.
extensionTestsEnv: { foo: 'bar' }
2019-04-13 22:36:15 +03:00
})
2019-03-14 21:33:54 +03:00
}
2019-06-27 15:38:45 +03:00
go();
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.