From ab321dd01b61288df3f2e2f80096c93afe74b15c Mon Sep 17 00:00:00 2001 From: Tihomir Culig Date: Sun, 16 Nov 2025 23:29:23 +0100 Subject: [PATCH 1/7] fix running test in VSCode UI --- .vscode/launch.json | 5 ++-- src/connectionController.ts | 1 + src/extension.ts | 25 +++++++++++++------ src/test/runTest.ts | 2 +- src/test/suite/connectionController.test.ts | 4 ++- ...ygroundSelectionCodeActionProvider.test.ts | 7 ------ src/test/suite/index.ts | 20 +++++++++++---- .../language/languageServerController.test.ts | 9 +++---- .../suite/views/webviewController.test.ts | 6 ++--- 9 files changed, 48 insertions(+), 31 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 533cbba63..263018a9c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -53,10 +53,11 @@ "--extensionTestsPath=${workspaceFolder}/out/test/suite" ], "env": { - "MOCHA_GREP": "${input:mochaGrep}" + "MOCHA_GREP": "${input:mochaGrep}", + "MDB_UNDER_TEST": "true" }, "outFiles": ["${workspaceFolder}/out/**/*.js"], - "preLaunchTask": "npm: compile:extension", + "preLaunchTask": "npm: compile:extension" } ], "inputs": [ diff --git a/src/connectionController.ts b/src/connectionController.ts index b68a5debf..87c7ecf15 100644 --- a/src/connectionController.ts +++ b/src/connectionController.ts @@ -729,6 +729,7 @@ export default class ConnectionController { if (!this._activeDataService) { log.error('Unable to disconnect: no active connection'); + this._disconnecting = false; return false; } diff --git a/src/extension.ts b/src/extension.ts index ae53f7f9b..e9ec1253e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -21,7 +21,9 @@ debug.log = log.debug.bind(log); import MDBExtensionController from './mdbExtensionController'; -let mdbExtension: MDBExtensionController; +let mdbExtension: MDBExtensionController | undefined; + +const isUnderTest = process.env.MDB_UNDER_TEST === 'true'; // Called when our extension is activated. // See "activationEvents" in `package.json` for the events that cause activation. @@ -51,13 +53,22 @@ export async function activate( }, }); - mdbExtension = new MDBExtensionController(context, { - shouldTrackTelemetry: true, - }); - await mdbExtension.activate(); + if (isUnderTest) { + log.info( + 'Skipping MDBExtensionController activation because MDB_UNDER_TEST is set.', + ); + return; + } - // Add our extension to a list of disposables for when we are deactivated. - context.subscriptions.push(mdbExtension); + if (!mdbExtension) { + mdbExtension = new MDBExtensionController(context, { + shouldTrackTelemetry: true, + }); + await mdbExtension.activate(); + + // Add our extension to a list of disposables for when we are deactivated. + context.subscriptions.push(mdbExtension); + } } // Called when our extension is deactivated. diff --git a/src/test/runTest.ts b/src/test/runTest.ts index 79278b9a1..3b07e0f0a 100644 --- a/src/test/runTest.ts +++ b/src/test/runTest.ts @@ -39,7 +39,7 @@ async function main(): Promise { // Download VS Code, unzip it and run the integration test await runTests({ - version: '1.103.2', // TODO(VSCODE-700) Once we fix the test setup issues, we should revert this to 'insiders' + version: 'insiders', extensionDevelopmentPath, extensionTestsPath, launchArgs: [testWorkspace, '--disable-extensions'], diff --git a/src/test/suite/connectionController.test.ts b/src/test/suite/connectionController.test.ts index 01eb20102..35a9bb2fb 100644 --- a/src/test/suite/connectionController.test.ts +++ b/src/test/suite/connectionController.test.ts @@ -42,7 +42,7 @@ const sleep = (ms: number): Promise => { }; suite('Connection Controller Test Suite', function () { - this.timeout(5000); + this.timeout(10000); const extensionContextStub = new ExtensionContextStub(); const testStorageController = new StorageController(extensionContextStub); @@ -73,6 +73,8 @@ suite('Connection Controller Test Suite', function () { extensionContextStub._workspaceState = {}; extensionContextStub._globalState = {}; + testConnectionController.cancelConnectionAttempt(); + await testConnectionController.disconnect(); testConnectionController.clearAllConnections(); diff --git a/src/test/suite/editors/playgroundSelectionCodeActionProvider.test.ts b/src/test/suite/editors/playgroundSelectionCodeActionProvider.test.ts index cd00309fd..c1c3d5e56 100644 --- a/src/test/suite/editors/playgroundSelectionCodeActionProvider.test.ts +++ b/src/test/suite/editors/playgroundSelectionCodeActionProvider.test.ts @@ -3,7 +3,6 @@ import { beforeEach, afterEach } from 'mocha'; import chai from 'chai'; import sinon from 'sinon'; import PlaygroundSelectionCodeActionProvider from '../../../editors/playgroundSelectionCodeActionProvider'; -import { LanguageServerController } from '../../../language'; import { mdbTestExtension } from '../stubbableMdbExtension'; import { PlaygroundController } from '../../../editors'; import { TEST_DATABASE_URI } from '../dbTestHelper'; @@ -32,11 +31,6 @@ suite('Playground Selection Code Action Provider Test Suite', function () { let testActiveTextEditor; beforeEach(async () => { - sandbox.replace( - mdbTestExtension.testExtensionController, - '_languageServerController', - new LanguageServerController(extensionContextStub), - ); sandbox.stub(vscode.window, 'showInformationMessage'); sandbox.stub( mdbTestExtension.testExtensionController._telemetryService, @@ -79,7 +73,6 @@ suite('Playground Selection Code Action Provider Test Suite', function () { .getConfiguration('mdb') .update('confirmRunAll', false); - await mdbTestExtension.testExtensionController._languageServerController.startLanguageServer(); await mdbTestExtension.testExtensionController._playgroundController._activeConnectionChanged(); testActiveTextEditor = sandbox.stub(vscode.window, 'activeTextEditor'); diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts index e3bbec7dd..13de8b55e 100644 --- a/src/test/suite/index.ts +++ b/src/test/suite/index.ts @@ -54,11 +54,21 @@ export async function run(): Promise { try { // Run the mocha test. mocha.run((failures) => { - if (failures > 0) { - e(new Error(`${failures} tests failed.`)); - } else { - c(); - } + // Deactivate the extension to properly clean up the language server + void mdbTestExtension.testExtensionController + .deactivate() + .then(() => { + if (failures > 0) { + e(new Error(`${failures} tests failed.`)); + } else { + c(); + } + }) + .catch((deactivateErr) => { + console.error('Error deactivating extension:'); + console.error(deactivateErr); + e(deactivateErr); + }); }); } catch (mochaRunErr) { console.error('Error running mocha tests:'); diff --git a/src/test/suite/language/languageServerController.test.ts b/src/test/suite/language/languageServerController.test.ts index df406b942..57d4a4b1d 100644 --- a/src/test/suite/language/languageServerController.test.ts +++ b/src/test/suite/language/languageServerController.test.ts @@ -11,7 +11,6 @@ import chaiAsPromised from 'chai-as-promised'; import PlaygroundSelectionCodeActionProvider from '../../../editors/playgroundSelectionCodeActionProvider'; import ConnectionController from '../../../connectionController'; import EditDocumentCodeLensProvider from '../../../editors/editDocumentCodeLensProvider'; -import { LanguageServerController } from '../../../language'; import { mdbTestExtension } from '../stubbableMdbExtension'; import { PlaygroundController } from '../../../editors'; import PlaygroundResultProvider from '../../../editors/playgroundResultProvider'; @@ -21,6 +20,7 @@ import { TEST_DATABASE_URI } from '../dbTestHelper'; import { TelemetryService } from '../../../telemetry'; import { ExtensionContextStub } from '../stubs'; import ExportToLanguageCodeLensProvider from '../../../editors/exportToLanguageCodeLensProvider'; +import type { LanguageServerController } from '../../../language'; const expect = chai.expect; @@ -58,9 +58,9 @@ suite('Language Server Controller Test Suite', () => { const sandbox = sinon.createSandbox(); before(async () => { - languageServerControllerStub = new LanguageServerController( - extensionContextStub, - ); + languageServerControllerStub = + mdbTestExtension.testExtensionController._languageServerController; + const testExportToLanguageCodeLensProvider = new ExportToLanguageCodeLensProvider(testPlaygroundResultProvider); @@ -73,7 +73,6 @@ suite('Language Server Controller Test Suite', () => { playgroundSelectionCodeActionProvider: testCodeActionProvider, exportToLanguageCodeLensProvider: testExportToLanguageCodeLensProvider, }); - await languageServerControllerStub.startLanguageServer(); await testPlaygroundController._activeConnectionChanged(); }); diff --git a/src/test/suite/views/webviewController.test.ts b/src/test/suite/views/webviewController.test.ts index b5ae67721..a6cdf6ae2 100644 --- a/src/test/suite/views/webviewController.test.ts +++ b/src/test/suite/views/webviewController.test.ts @@ -157,9 +157,9 @@ suite('Webview Test Suite', () => { suite('when oidc device auth flow setting is enabled', function () { let originalDeviceAuthFlow; before(async function () { - originalDeviceAuthFlow = vscode.workspace.getConfiguration( - 'mdb.showOIDCDeviceAuthFlow', - ); + originalDeviceAuthFlow = vscode.workspace + .getConfiguration('mdb') + .get('showOIDCDeviceAuthFlow'); await vscode.workspace .getConfiguration('mdb') From 913f5b2d75afddb09db32605c8c78596e208b8e1 Mon Sep 17 00:00:00 2001 From: Tihomir Culig Date: Sun, 16 Nov 2025 23:37:32 +0100 Subject: [PATCH 2/7] Update github actions --- .github/workflows/actions/test-and-build/action.yaml | 1 + .github/workflows/draft-release.yaml | 1 + .github/workflows/test-and-build-from-fork.yaml | 1 + .github/workflows/test-and-build.yaml | 1 + 4 files changed, 4 insertions(+) diff --git a/.github/workflows/actions/test-and-build/action.yaml b/.github/workflows/actions/test-and-build/action.yaml index b847cb0e0..9abd9db62 100644 --- a/.github/workflows/actions/test-and-build/action.yaml +++ b/.github/workflows/actions/test-and-build/action.yaml @@ -68,6 +68,7 @@ runs: - name: Run Tests env: NODE_OPTIONS: "--max_old_space_size=4096" + MDB_UNDER_TEST: "true" run: | npm run test shell: bash diff --git a/.github/workflows/draft-release.yaml b/.github/workflows/draft-release.yaml index 70c290198..f6f450d18 100644 --- a/.github/workflows/draft-release.yaml +++ b/.github/workflows/draft-release.yaml @@ -96,6 +96,7 @@ jobs: GARASIGN_USERNAME: ${{ secrets.GARASIGN_USERNAME }} SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} + MDB_UNDER_TEST: "true" - name: Create Draft Release run: | diff --git a/.github/workflows/test-and-build-from-fork.yaml b/.github/workflows/test-and-build-from-fork.yaml index 44aad4fe1..f07ea1eef 100644 --- a/.github/workflows/test-and-build-from-fork.yaml +++ b/.github/workflows/test-and-build-from-fork.yaml @@ -40,4 +40,5 @@ jobs: env: NODE_OPTIONS: "--max_old_space_size=4096" SEGMENT_KEY: "test-segment-key" + MDB_UNDER_TEST: "true" run: npm run test diff --git a/.github/workflows/test-and-build.yaml b/.github/workflows/test-and-build.yaml index 5399eef5f..1316043a3 100644 --- a/.github/workflows/test-and-build.yaml +++ b/.github/workflows/test-and-build.yaml @@ -48,3 +48,4 @@ jobs: GARASIGN_USERNAME: ${{ secrets.GARASIGN_USERNAME }} SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} + MDB_UNDER_TEST: "true" From 621c80166d101cf001e4c35d44d4c044ef1eaaa2 Mon Sep 17 00:00:00 2001 From: Tihomir Culig Date: Mon, 17 Nov 2025 11:32:31 +0100 Subject: [PATCH 3/7] Add note explaining the early return --- src/extension.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index e9ec1253e..6506a0414 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -53,6 +53,8 @@ export async function activate( }, }); + // Solution to VSCODE-700. If we are running tests, don't activate the extension. + // This avoids registering multiple providers when running the tests, which causes errors in recent versions of vscode. if (isUnderTest) { log.info( 'Skipping MDBExtensionController activation because MDB_UNDER_TEST is set.', From b592233558bccf40c8ba4dcac79fc5a8c2407431 Mon Sep 17 00:00:00 2001 From: Tihomir Culig Date: Mon, 17 Nov 2025 11:33:40 +0100 Subject: [PATCH 4/7] Update src/extension.ts Co-authored-by: Himanshu Singh --- src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 6506a0414..9f42d750a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -23,7 +23,7 @@ import MDBExtensionController from './mdbExtensionController'; let mdbExtension: MDBExtensionController | undefined; -const isUnderTest = process.env.MDB_UNDER_TEST === 'true'; +const isUnderTest = process.env.NODE_ENV === "test" && process.env.MDB_UNDER_TEST === 'true'; // Called when our extension is activated. // See "activationEvents" in `package.json` for the events that cause activation. From 07f26cd131a88e09af9a2a1d614f102db6ab67a4 Mon Sep 17 00:00:00 2001 From: Tihomir Culig Date: Mon, 17 Nov 2025 11:53:39 +0100 Subject: [PATCH 5/7] Add MDB_UNDER_TEST flag to test-extension script --- package.json | 2 +- src/extension.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index dae69987e..7ae138786 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "watch:extension-bundles": "webpack --mode development --watch", "pretest": "npm run compile", "test": "npm run test-webview && npm run test-extension", - "test-extension": "cross-env NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js", + "test-extension": "cross-env MDB_UNDER_TEST=true NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js", "test-webview": "mocha -r ts-node/register --grep=\"${MOCHA_GREP}\" --file ./src/test/setup-webview.ts src/test/suite/views/webview-app/**/*.test.tsx", "ai-accuracy-tests": "env TS_NODE_FILES=true mocha -r ts-node/register --grep=\"${MOCHA_GREP}\" --file ./src/test/ai-accuracy-tests/test-setup.ts ./src/test/ai-accuracy-tests/ai-accuracy-tests.ts", "analyze-bundle": "webpack --mode production --analyze", diff --git a/src/extension.ts b/src/extension.ts index 9f42d750a..e245ab43e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -23,7 +23,8 @@ import MDBExtensionController from './mdbExtensionController'; let mdbExtension: MDBExtensionController | undefined; -const isUnderTest = process.env.NODE_ENV === "test" && process.env.MDB_UNDER_TEST === 'true'; +const isUnderTest = + process.env.NODE_ENV === 'test' || process.env.MDB_UNDER_TEST === 'true'; // Called when our extension is activated. // See "activationEvents" in `package.json` for the events that cause activation. From e9f58ec63b3672c9aa71855b9890c8b6840327b4 Mon Sep 17 00:00:00 2001 From: Tihomir Culig Date: Wed, 19 Nov 2025 14:18:28 +0100 Subject: [PATCH 6/7] Rename MDB_UNDER_TEST to MDB_IS_TEST --- .github/workflows/actions/test-and-build/action.yaml | 2 +- .github/workflows/draft-release.yaml | 2 +- .github/workflows/test-and-build-from-fork.yaml | 2 +- .github/workflows/test-and-build.yaml | 2 +- .vscode/launch.json | 2 +- package.json | 2 +- src/extension.ts | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/actions/test-and-build/action.yaml b/.github/workflows/actions/test-and-build/action.yaml index 9abd9db62..f10658fa0 100644 --- a/.github/workflows/actions/test-and-build/action.yaml +++ b/.github/workflows/actions/test-and-build/action.yaml @@ -68,7 +68,7 @@ runs: - name: Run Tests env: NODE_OPTIONS: "--max_old_space_size=4096" - MDB_UNDER_TEST: "true" + MDB_IS_TEST: "true" run: | npm run test shell: bash diff --git a/.github/workflows/draft-release.yaml b/.github/workflows/draft-release.yaml index f6f450d18..0a5cf2990 100644 --- a/.github/workflows/draft-release.yaml +++ b/.github/workflows/draft-release.yaml @@ -96,7 +96,7 @@ jobs: GARASIGN_USERNAME: ${{ secrets.GARASIGN_USERNAME }} SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} - MDB_UNDER_TEST: "true" + MDB_IS_TEST: "true" - name: Create Draft Release run: | diff --git a/.github/workflows/test-and-build-from-fork.yaml b/.github/workflows/test-and-build-from-fork.yaml index f07ea1eef..62493f282 100644 --- a/.github/workflows/test-and-build-from-fork.yaml +++ b/.github/workflows/test-and-build-from-fork.yaml @@ -40,5 +40,5 @@ jobs: env: NODE_OPTIONS: "--max_old_space_size=4096" SEGMENT_KEY: "test-segment-key" - MDB_UNDER_TEST: "true" + MDB_IS_TEST: "true" run: npm run test diff --git a/.github/workflows/test-and-build.yaml b/.github/workflows/test-and-build.yaml index 1316043a3..4aa0e1b29 100644 --- a/.github/workflows/test-and-build.yaml +++ b/.github/workflows/test-and-build.yaml @@ -48,4 +48,4 @@ jobs: GARASIGN_USERNAME: ${{ secrets.GARASIGN_USERNAME }} SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} - MDB_UNDER_TEST: "true" + MDB_IS_TEST: "true" diff --git a/.vscode/launch.json b/.vscode/launch.json index 263018a9c..95c2c7a51 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -54,7 +54,7 @@ ], "env": { "MOCHA_GREP": "${input:mochaGrep}", - "MDB_UNDER_TEST": "true" + "MDB_IS_TEST": "true" }, "outFiles": ["${workspaceFolder}/out/**/*.js"], "preLaunchTask": "npm: compile:extension" diff --git a/package.json b/package.json index 7ae138786..0f168de13 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "watch:extension-bundles": "webpack --mode development --watch", "pretest": "npm run compile", "test": "npm run test-webview && npm run test-extension", - "test-extension": "cross-env MDB_UNDER_TEST=true NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js", + "test-extension": "cross-env MDB_IS_TEST=true NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js", "test-webview": "mocha -r ts-node/register --grep=\"${MOCHA_GREP}\" --file ./src/test/setup-webview.ts src/test/suite/views/webview-app/**/*.test.tsx", "ai-accuracy-tests": "env TS_NODE_FILES=true mocha -r ts-node/register --grep=\"${MOCHA_GREP}\" --file ./src/test/ai-accuracy-tests/test-setup.ts ./src/test/ai-accuracy-tests/ai-accuracy-tests.ts", "analyze-bundle": "webpack --mode production --analyze", diff --git a/src/extension.ts b/src/extension.ts index e245ab43e..f6ef549a9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -24,7 +24,7 @@ import MDBExtensionController from './mdbExtensionController'; let mdbExtension: MDBExtensionController | undefined; const isUnderTest = - process.env.NODE_ENV === 'test' || process.env.MDB_UNDER_TEST === 'true'; + process.env.NODE_ENV === 'test' || process.env.MDB_IS_TEST === 'true'; // Called when our extension is activated. // See "activationEvents" in `package.json` for the events that cause activation. @@ -58,7 +58,7 @@ export async function activate( // This avoids registering multiple providers when running the tests, which causes errors in recent versions of vscode. if (isUnderTest) { log.info( - 'Skipping MDBExtensionController activation because MDB_UNDER_TEST is set.', + 'Skipping MDBExtensionController activation because MDB_IS_TEST is set.', ); return; } From 104833db33b8c5633628c1e70ea0bee9a40a3676 Mon Sep 17 00:00:00 2001 From: Tihomir Culig Date: Wed, 19 Nov 2025 14:30:23 +0100 Subject: [PATCH 7/7] Remove NODE_ENV check --- src/extension.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index f6ef549a9..a4c10e239 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -23,8 +23,7 @@ import MDBExtensionController from './mdbExtensionController'; let mdbExtension: MDBExtensionController | undefined; -const isUnderTest = - process.env.NODE_ENV === 'test' || process.env.MDB_IS_TEST === 'true'; +const isUnderTest = process.env.MDB_IS_TEST === 'true'; // Called when our extension is activated. // See "activationEvents" in `package.json` for the events that cause activation.