Skip to content

Commit f45a4c7

Browse files
test: VSCode test setup and switch to insiders VSCODE-700 (#1186)
Co-authored-by: Himanshu Singh <himanshu.singhs@outlook.in>
1 parent ae20849 commit f45a4c7

File tree

14 files changed

+55
-32
lines changed

14 files changed

+55
-32
lines changed

.github/workflows/actions/test-and-build/action.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ runs:
6868
- name: Run Tests
6969
env:
7070
NODE_OPTIONS: "--max_old_space_size=4096"
71+
MDB_IS_TEST: "true"
7172
run: |
7273
npm run test
7374
shell: bash

.github/workflows/draft-release.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ jobs:
9696
GARASIGN_USERNAME: ${{ secrets.GARASIGN_USERNAME }}
9797
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
9898
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
99+
MDB_IS_TEST: "true"
99100

100101
- name: Create Draft Release
101102
run: |

.github/workflows/test-and-build-from-fork.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ jobs:
4040
env:
4141
NODE_OPTIONS: "--max_old_space_size=4096"
4242
SEGMENT_KEY: "test-segment-key"
43+
MDB_IS_TEST: "true"
4344
run: npm run test

.github/workflows/test-and-build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ jobs:
4848
GARASIGN_USERNAME: ${{ secrets.GARASIGN_USERNAME }}
4949
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
5050
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
51+
MDB_IS_TEST: "true"

.vscode/launch.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@
5353
"--extensionTestsPath=${workspaceFolder}/out/test/suite"
5454
],
5555
"env": {
56-
"MOCHA_GREP": "${input:mochaGrep}"
56+
"MOCHA_GREP": "${input:mochaGrep}",
57+
"MDB_IS_TEST": "true"
5758
},
5859
"outFiles": ["${workspaceFolder}/out/**/*.js"],
59-
"preLaunchTask": "npm: compile:extension",
60+
"preLaunchTask": "npm: compile:extension"
6061
}
6162
],
6263
"inputs": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"watch:extension-bundles": "webpack --mode development --watch",
5353
"pretest": "npm run compile",
5454
"test": "npm run test-webview && npm run test-extension",
55-
"test-extension": "cross-env NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js",
55+
"test-extension": "cross-env MDB_IS_TEST=true NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js",
5656
"test-webview": "mocha -r ts-node/register --grep=\"${MOCHA_GREP}\" --file ./src/test/setup-webview.ts src/test/suite/views/webview-app/**/*.test.tsx",
5757
"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",
5858
"analyze-bundle": "webpack --mode production --analyze",

src/connectionController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ export default class ConnectionController {
729729

730730
if (!this._activeDataService) {
731731
log.error('Unable to disconnect: no active connection');
732+
this._disconnecting = false;
732733
return false;
733734
}
734735

src/extension.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ debug.log = log.debug.bind(log);
2121

2222
import MDBExtensionController from './mdbExtensionController';
2323

24-
let mdbExtension: MDBExtensionController;
24+
let mdbExtension: MDBExtensionController | undefined;
25+
26+
const isUnderTest = process.env.MDB_IS_TEST === 'true';
2527

2628
// Called when our extension is activated.
2729
// See "activationEvents" in `package.json` for the events that cause activation.
@@ -51,13 +53,24 @@ export async function activate(
5153
},
5254
});
5355

54-
mdbExtension = new MDBExtensionController(context, {
55-
shouldTrackTelemetry: true,
56-
});
57-
await mdbExtension.activate();
56+
// Solution to VSCODE-700. If we are running tests, don't activate the extension.
57+
// This avoids registering multiple providers when running the tests, which causes errors in recent versions of vscode.
58+
if (isUnderTest) {
59+
log.info(
60+
'Skipping MDBExtensionController activation because MDB_IS_TEST is set.',
61+
);
62+
return;
63+
}
5864

59-
// Add our extension to a list of disposables for when we are deactivated.
60-
context.subscriptions.push(mdbExtension);
65+
if (!mdbExtension) {
66+
mdbExtension = new MDBExtensionController(context, {
67+
shouldTrackTelemetry: true,
68+
});
69+
await mdbExtension.activate();
70+
71+
// Add our extension to a list of disposables for when we are deactivated.
72+
context.subscriptions.push(mdbExtension);
73+
}
6174
}
6275

6376
// Called when our extension is deactivated.

src/test/runTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async function main(): Promise<any> {
3939

4040
// Download VS Code, unzip it and run the integration test
4141
await runTests({
42-
version: '1.103.2', // TODO(VSCODE-700) Once we fix the test setup issues, we should revert this to 'insiders'
42+
version: 'insiders',
4343
extensionDevelopmentPath,
4444
extensionTestsPath,
4545
launchArgs: [testWorkspace, '--disable-extensions'],

src/test/suite/connectionController.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const sleep = (ms: number): Promise<void> => {
4242
};
4343

4444
suite('Connection Controller Test Suite', function () {
45-
this.timeout(5000);
45+
this.timeout(10000);
4646

4747
const extensionContextStub = new ExtensionContextStub();
4848
const testStorageController = new StorageController(extensionContextStub);
@@ -73,6 +73,8 @@ suite('Connection Controller Test Suite', function () {
7373
extensionContextStub._workspaceState = {};
7474
extensionContextStub._globalState = {};
7575

76+
testConnectionController.cancelConnectionAttempt();
77+
7678
await testConnectionController.disconnect();
7779
testConnectionController.clearAllConnections();
7880

0 commit comments

Comments
 (0)