Skip to content

Commit f83d54b

Browse files
committed
Prevent telemetry popup from making the test instance hang
1 parent a636900 commit f83d54b

5 files changed

Lines changed: 50 additions & 15 deletions

File tree

.vscode/launch.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"env": {
2121
// change to 'true' debug the IDE or Query servers
2222
"IDE_SERVER_JAVA_DEBUG": "false",
23-
"QUERY_SERVER_JAVA_DEBUG": "false",
23+
"QUERY_SERVER_JAVA_DEBUG": "false"
2424
}
2525
},
2626
{
@@ -47,7 +47,10 @@
4747
"stopOnEntry": false,
4848
"sourceMaps": true,
4949
"console": "integratedTerminal",
50-
"internalConsoleOptions": "neverOpen"
50+
"internalConsoleOptions": "neverOpen",
51+
"env": {
52+
"VSCODE_TEST": "true"
53+
}
5154
},
5255
{
5356
"name": "Launch Integration Tests - No Workspace (vscode-codeql)",
@@ -63,6 +66,9 @@
6366
"outFiles": [
6467
"${workspaceRoot}/extensions/ql-vscode/out/**/*.js",
6568
],
69+
"env": {
70+
"VSCODE_TEST": "true"
71+
}
6672
},
6773
{
6874
"name": "Launch Integration Tests - Minimal Workspace (vscode-codeql)",
@@ -79,6 +85,9 @@
7985
"outFiles": [
8086
"${workspaceRoot}/extensions/ql-vscode/out/**/*.js",
8187
],
88+
"env": {
89+
"VSCODE_TEST": "true"
90+
}
8291
},
8392
{
8493
"name": "Launch Integration Tests - With CLI",
@@ -91,13 +100,16 @@
91100
"${workspaceRoot}/extensions/ql-vscode/src/vscode-tests/cli-integration/data",
92101
// Add a path to a checked out instance of the codeql repository so the libraries are
93102
// available in the workspace for the tests.
94-
// "${workspaceRoot}/../codeql"
103+
"${workspaceRoot}/../codeql"
95104
],
96105
"stopOnEntry": false,
97106
"sourceMaps": true,
98107
"outFiles": [
99108
"${workspaceRoot}/extensions/ql-vscode/out/**/*.js",
100109
],
110+
"env": {
111+
"VSCODE_TEST": "true"
112+
}
101113
}
102114
]
103115
}

extensions/ql-vscode/src/helpers.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ async function internalShowAndLog(
8080
return result;
8181
}
8282

83+
/**
84+
* Always avoid modal dialogs during tests. During tests, the VSCODE_TEST
85+
* env variable is set. Use that to override the requested value of modal.
86+
*
87+
* Modals prevent the vscode process from ending when tests are complete.
88+
*
89+
* @param modal
90+
*/
91+
function showModal(modal: boolean) {
92+
const isTest = !!process.env.VSCODE_TEST;
93+
return !isTest && modal;
94+
}
95+
8396
/**
8497
* Opens a modal dialog for the user to make a yes/no choice.
8598
*
@@ -95,7 +108,7 @@ async function internalShowAndLog(
95108
export async function showBinaryChoiceDialog(message: string, modal = true): Promise<boolean | undefined> {
96109
const yesItem = { title: 'Yes', isCloseAffordance: false };
97110
const noItem = { title: 'No', isCloseAffordance: true };
98-
const chosenItem = await Window.showInformationMessage(message, { modal }, yesItem, noItem);
111+
const chosenItem = await Window.showInformationMessage(message, { modal: showModal(modal) }, yesItem, noItem);
99112
if (!chosenItem) {
100113
return undefined;
101114
}
@@ -106,8 +119,6 @@ export async function showBinaryChoiceDialog(message: string, modal = true): Pro
106119
* Opens a modal dialog for the user to make a yes/no choice.
107120
*
108121
* @param message The message to show.
109-
* @param modal If true (the default), show a modal dialog box, otherwise dialog is non-modal and can
110-
* be closed even if the user does not make a choice.
111122
*
112123
* @return
113124
* `true` if the user clicks 'Yes',
@@ -124,7 +135,7 @@ export async function showBinaryChoiceWithUrlDialog(message: string, url: string
124135
// To prevent an infinite loop, if the user clicks 'more information' 5 times, close the dialog and return cancelled
125136
let count = 0;
126137
do {
127-
chosenItem = await Window.showInformationMessage(message, { modal: true }, urlItem, yesItem, noItem);
138+
chosenItem = await Window.showInformationMessage(message, { modal: showModal(true) }, urlItem, yesItem, noItem);
128139
if (chosenItem === urlItem) {
129140
await env.openExternal(Uri.parse(url, true));
130141
}
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import * as assert from 'assert';
2-
import * as vscode from 'vscode';
1+
import { expect } from 'chai';
2+
import { Extension, extensions } from 'vscode';
3+
import { CodeQLExtensionInterface } from '../../extension';
34

45
// Note that this may open the most recent VSCode workspace.
56
describe('launching with no specified workspace', () => {
6-
const ext = vscode.extensions.getExtension('GitHub.vscode-codeql');
7-
it('should install the extension', () => {
8-
assert(ext);
7+
let ext: Extension<CodeQLExtensionInterface> | undefined;
8+
beforeEach(async () => {
9+
ext = await extensions.getExtension<CodeQLExtensionInterface>('GitHub.vscode-codeql');
910
});
10-
it('should not activate the extension at first', () => {
11-
assert(ext!.isActive === false);
11+
12+
it('should not activate the extension at first', async () => {
13+
expect(ext).not.to.be.undefined;
14+
expect(ext!.isActive).to.be.false;
1215
});
1316
});

extensions/ql-vscode/src/vscode-tests/no-workspace/telemetry.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ describe('telemetry reporting', function() {
6767
}
6868
});
6969

70+
it('should avoid modal dialogs', () => {
71+
// This test ensures that modal dialogs will not show up. This is a cause of hanging
72+
// tests.
73+
expect(!!process.env.VSCODE_TEST).to.be.true;
74+
});
75+
7076
it('should initialize telemetry when both options are enabled', async () => {
7177
await telemetryListener.initialize();
7278

extensions/ql-vscode/src/vscode-tests/run-integration-tests.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ async function main() {
9696
vscodeExecutablePath,
9797
extensionDevelopmentPath,
9898
extensionTestsPath: path.resolve(__dirname, dir, 'index'),
99-
launchArgs
99+
launchArgs,
100+
extensionTestsEnv: {
101+
VSCODE_TEST: 'true'
102+
}
100103
}, 3);
101104
}
102105
} catch (err) {

0 commit comments

Comments
 (0)