Home > OS >  VSCode extension testing: Use `vscode.executeDefinitionProvider` in test
VSCode extension testing: Use `vscode.executeDefinitionProvider` in test

Time:09-29

Background

I'm trying to auto-test my VSCode extension. The extension works with python files and uses vscode.executeDefinitionProvider and vscode.executeDocumentSymbolProvider on them.

Problem

vscode.executeDefinitionProvider always returns [], vscode.executeDocumentSymbolProvider always returns undefined.

Notes

When running the same code in a debug session of the extension (no test session), the commands work flawless.

I ensured the extensions to be available during the test and even manually activated them with

let ext = vscode.extensions.getExtension("ms-python.python");
assert.notStrictEqual (ext, undefined);
await ext?.activate ();
ext = vscode.extensions.getExtension("ms-python.vscode-pylance");
assert.notStrictEqual (ext, undefined);
await ext?.activate ();

Question

How do I get the commands to succeed during automated test.

Edit: Workaround

Apparently VSCode takes its time to really activate the extensions. I could get it working placing a await sleep (10000); in index.ts::run () before return new Promise((c, e) => {.

While this is working, it's a really unstable workaround, Is there any way to make the code wait until the whole environment is fully loaded?

CodePudding user response:

Extension<T>::activate(): Thenable<T>

Returns: Thenable<T> - A promise that will resolve when this extension has been activated.

await ext?.activate();
  • Related