VSCode Extension/Testing: Mocking of class methods via Sinon stubs are working fine while debugging but not while running tests from command line

Viewed 298

I am mocking methods of controlprovider class using Sinon stubs. It is working fine when I debug these tests in VSCode but while I run tests from the command line, Sinon stub mocking doesn't happen. Anything I am missing?

Test file

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();
    });
});

Launch debug configuration

    {
        "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"
},
0 Answers
Related