首页 > 解决方案 > 如何解决我在安装 vscode 以测试我的扩展程序时遇到的错误?

问题描述

我现在从 github 模板做了一个 vscode 扩展来测试我必须根据指南运行这个命令

node ./node_modules/vscode/bin/test

哪个安装 vscode 来测试我的分机。但是安装后我得到的输出为

Downloading VS Code 1.54.3 into .vscode-test/vscode-1.54.3.
Downloading VS Code from: https://update.code.visualstudio.com/1.54.3/win32-archive/stable
Downloaded VS Code 1.54.3
Test error: Error: spawn E:\NewProj\glitter-ext\.vscode-test\vscode-1.54.3\Code.exe ENOENT
Exit code:   -4058
Done

Failed

在这我不确定我该怎么办?我的分机代码是

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

    console.log('Congratulations, your extension "hello-world-vscode-extension" is now active!');

    let disposable = vscode.commands.registerCommand('extension.sayHello', () => {
        vscode.window.showInformationMessage('Hello World!');
    });

    context.subscriptions.push(disposable);
}

编辑:

我以某种方式设法将 vscode 安装到./vscode-test文件夹中。现在我写了一个类似这样的测试文件

const { runTests } = require('vscode-test');
const path = require('path');

async function test() {
    try{
        await runTests({
            extensionPath: path.join(__dirname, "../dist/"),
            testRunnerPath: path.join(__dirname, "../.vscode-test/"),
            extensionDevelopmentPath: path.join(__dirname, "../dist/")
        })
    }catch(e){
        console.error(e);
    }
}

test();

当我运行这个文件时,这个文件被命名为test/index.js现在一切都很好,vscode打开进行测试,并以同样的速度关闭并将控制台显示为失败:

Exit code:   1
Done

Failed

标签: typescriptvisual-studio-codevscode-extensions

解决方案


通过使用额外的启动配置来使用当前 VSC并写入index.(ts/js)文件和您的测试文件

从运行/调试栏中选择此配置,然后按 F5。

现在无需下载 VSC。


推荐阅读