VSCode扩展/测试:通过Sinon存根对类方法进行模拟在调试时工作正常,但在从命令行运行测试时却无法正常工作

问题描述

我正在使用Sinon存根模拟controlprovider类的方法。当我在VSCode中调试这些测试时,它工作正常,但是当我从命令行运行测试时,Sinan存根模拟不会发生。我有什么想念吗?

测试文件

context('Should configure pipeline',function () {
    it('configure pipeline',async function () {
        this.timeout(0);
        await sleep(5000);
        await vscode.extensions.getExtension(extensionId).activate();
        let mockGetInput,mockShowQuickPick,mockShowInformationMessage;
        mockGetInput = sinon.stub(ControlProvider.prototype,'showInputBox');
        mockGetInput.onFirstCall().resolves('text');

        mockShowQuickPick = sinon.stub(ControlProvider.prototype,'showQuickPick');
        mockShowQuickPick
            .onFirstCall().resolves(data1)
            .onSecondCall().resolves(data2)

        mockShowInformationMessage = sinon.stub(ControlProvider.prototype,'showInformationBox');
        mockShowInformationMessage.onFirstCall().resolves("Done");

        // This sleep is added because otherwise the tests run via cmd exits before running executeCommand. Unable to find root cause of this issue.
        await sleep(2000);
        await vscode.commands.executeCommand("configure-cicd-pipeline");

        sinon.assert.calledOnce(mockGetInput);
        sinon.assert.calledTwice(mockShowQuickPick);
        sinon.assert.calledOnce(mockShowInformationMessage);

    });

    after(() => {
        sinon.restore();
    });
});

启动调试配置

    {
        "name": "Extension Tests","type": "extensionHost","request": "launch","runtimeExecutable": "${execPath}","args": [
            "${workspaceRoot}/out/configure/test/test-fixtures/","--extensionDevelopmentPath=${workspaceFolder}","--extensionTestsPath=${workspaceFolder}/out/configure/test"
        ],"outFiles": [
            "${workspaceFolder}/out/configure/test/**/*.js"
        ]
    },

package.json

"scripts": {
    "vscode:prepublish": "npm run compile","compile": "tsc -p ./ && node copyStaticFiles.js","watch": "node copyStaticFiles.js && tsc -watch -p ./","pretest": "npm run compile","test": "cp -r ./src/configure/test/test-fixtures/ ./out/configure/test/test-fixtures/ && node ./out/configure/test/runTest.js"
},

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)