How to access extension in tests? #2563
-
I am using test('Test for command', async () => {
const commands = await vscode.commands.getCommands(true);
assert.ok(commands.includes('extension.helloWorld'), 'Command ID not found in the registered commands');
}); I get an error stating that the command is not found. I ran the tests via |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @eschricker , I'm not an expert in testing extensions, but I have a few tests on my extensions. For your use case, as a startup, I guess you only need to Add this to the test suite. A reference to an suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
// add below code
let extension: vscode.Extension<any>;
suiteSetup(() => {
extension = vscode.extensions.getExtension('vscode-samples.helloworld-sample') as vscode.Extension<any>;
});
test('Activation test', async () => {
await extension.activate();
assert.strictEqual(extension.isActive, true);
}); On the other hand, if you need to interact with your commands and so on, take a look at one of my extensions (https://github.com/alefragnani/vscode-copy-word/blob/master/src/test/suite/commands.test.ts). It is a simple extension, fairly easy to build and run. Hope this helps |
Beta Was this translation helpful? Give feedback.
Hi @eschricker ,
I'm not an expert in testing extensions, but I have a few tests on my extensions. For your use case, as a startup, I guess you only need to
get
the extension.Add this to the test suite. A reference to an
extension
, which is filled in thesuiteSetup
.