vendredi 1 novembre 2019

VSCode - Typescript - Debug / Test

I wrote an extension, and I want to test it. One function needs a vscode.TextEditor. Using this launch config:

{
"name": "Extension Test",
    "type": "extensionHost",
    "request": "launch",
    "runtimeExecutable": "${execPath}",
    "args": [
        "--extensionDevelopmentPath=${workspaceFolder}",
        "--extensionTestsPath=${workspaceFolder}/out/extension/tests/suite/index"
    ],
    "outFiles": [
        "${workspaceFolder}/out/extension/tests/**/*.js"
    ]
}

I am using vscode-test.runTests and mocha. In my test file I try to create a TextEditor, by doing:

let file: vscode.Uri;
file = vscode.Uri.parse('file:' + __dirname + '/test.txt');
vscode.workspace.openTextDocument(file).then(doc => {
    vscode.window.showTextDocument(doc).then(editor => {
        console.log(editor.document.getText);
    });
}, () => {
    console.log('something went wrong')
});

the string I used in the parse method of vscode.Uri is a Uri of a test.txt file I created with some test data.

The problem is, that the openTextDocument always gets to the onrejected function ('something went wrong').

Am doing something wrong? Why is that the case?

Aucun commentaire:

Enregistrer un commentaire