Skip to content

Commit 11bc465

Browse files
committed
Fix and re-enable variant analysis submission integration tests
1 parent b44c602 commit 11bc465

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed

extensions/ql-vscode/src/common/commands.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ export type MockGitHubApiServerCommands = {
348348
"codeQL.mockGitHubApiServer.startRecording": () => Promise<void>;
349349
"codeQL.mockGitHubApiServer.saveScenario": () => Promise<void>;
350350
"codeQL.mockGitHubApiServer.cancelRecording": () => Promise<void>;
351-
"codeQL.mockGitHubApiServer.loadScenario": () => Promise<void>;
351+
"codeQL.mockGitHubApiServer.loadScenario": (
352+
scenario?: string,
353+
) => Promise<void>;
352354
"codeQL.mockGitHubApiServer.unloadScenario": () => Promise<void>;
353355
};
354356

extensions/ql-vscode/src/common/mock-gh-api/vscode/vscode-mock-gh-api-server.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,33 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
6363
);
6464
}
6565

66-
public async loadScenario(): Promise<void> {
66+
public async loadScenario(scenario?: string): Promise<void> {
6767
const scenariosPath = await this.getScenariosPath();
6868
if (!scenariosPath) {
6969
return;
7070
}
7171

72-
const scenarioNames = await this.server.getScenarioNames(scenariosPath);
73-
const scenarioQuickPickItems = scenarioNames.map((s) => ({ label: s }));
74-
const quickPickOptions = {
75-
placeHolder: "Select a scenario to load",
76-
};
77-
const selectedScenario = await window.showQuickPick<QuickPickItem>(
78-
scenarioQuickPickItems,
79-
quickPickOptions,
80-
);
81-
if (!selectedScenario) {
82-
return;
72+
let scenarioName = scenario;
73+
if (!scenarioName) {
74+
const scenarioNames = await this.server.getScenarioNames(scenariosPath);
75+
const scenarioQuickPickItems = scenarioNames.map((s) => ({ label: s }));
76+
const quickPickOptions = {
77+
placeHolder: "Select a scenario to load",
78+
};
79+
const selectedScenario = await window.showQuickPick<QuickPickItem>(
80+
scenarioQuickPickItems,
81+
quickPickOptions,
82+
);
83+
if (!selectedScenario) {
84+
return;
85+
}
86+
87+
scenarioName = selectedScenario.label;
8388
}
8489

85-
const scenarioName = selectedScenario.label;
90+
if (!this.server.isListening && this.app.mode === AppMode.Test) {
91+
await this.startServer();
92+
}
8693

8794
await this.server.loadScenario(scenarioName, scenariosPath);
8895

@@ -94,20 +101,24 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
94101
true,
95102
);
96103

97-
await window.showInformationMessage(`Loaded scenario '${scenarioName}'`);
104+
void window.showInformationMessage(`Loaded scenario '${scenarioName}'`);
98105
}
99106

100107
public async unloadScenario(): Promise<void> {
101108
if (!this.server.isScenarioLoaded) {
102-
await window.showInformationMessage("No scenario currently loaded");
109+
void window.showInformationMessage("No scenario currently loaded");
103110
} else {
104111
await this.server.unloadScenario();
105112
await this.app.commands.execute(
106113
"setContext",
107114
"codeQL.mockGitHubApiServer.scenarioLoaded",
108115
false,
109116
);
110-
await window.showInformationMessage("Unloaded scenario");
117+
void window.showInformationMessage("Unloaded scenario");
118+
}
119+
120+
if (this.server.isListening && this.app.mode === AppMode.Test) {
121+
await this.stopServer();
111122
}
112123
}
113124

@@ -139,7 +150,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
139150
true,
140151
);
141152

142-
await window.showInformationMessage(
153+
void window.showInformationMessage(
143154
'Recording scenario. To save the scenario, use the "CodeQL Mock GitHub API Server: Save Scenario" command.',
144155
);
145156
}
@@ -221,7 +232,10 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
221232
return scenariosPath;
222233
}
223234

224-
if (this.app.mode === AppMode.Development) {
235+
if (
236+
this.app.mode === AppMode.Development ||
237+
this.app.mode === AppMode.Test
238+
) {
225239
const developmentScenariosPath = path.join(
226240
this.app.extensionPath,
227241
"src/common/mock-gh-api/scenarios",

extensions/ql-vscode/test/vscode-tests/cli-integration/variant-analysis/variant-analysis-submission-integration.test.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ import { resolve } from "path";
33
import type { TextDocument } from "vscode";
44
import { authentication, commands, window, workspace } from "vscode";
55

6-
import { MockGitHubApiServer } from "../../../../src/common/mock-gh-api/mock-gh-api-server";
76
import { mockedQuickPickItem } from "../../utils/mocking.helpers";
87
import { setRemoteControllerRepo } from "../../../../src/config";
98
import { getActivatedExtension } from "../../global.helper";
109
import { createVSCodeCommandManager } from "../../../../src/common/vscode/commands";
1110
import type { AllCommands } from "../../../../src/common/commands";
1211

13-
const mockServer = new MockGitHubApiServer();
14-
beforeAll(() => mockServer.startServer("bypass"));
15-
afterEach(() => mockServer.unloadScenario());
16-
afterAll(() => mockServer.stopServer());
17-
1812
async function showQlDocument(name: string): Promise<TextDocument> {
1913
const folderPath = workspace.workspaceFolders![0].uri.fsPath;
2014
const documentPath = resolve(folderPath, name);
@@ -24,7 +18,7 @@ async function showQlDocument(name: string): Promise<TextDocument> {
2418
}
2519

2620
// MSW can't intercept fetch requests made in VS Code, so we are skipping these tests for now
27-
describe.skip("Variant Analysis Submission Integration", () => {
21+
describe("Variant Analysis Submission Integration", () => {
2822
const commandManager = createVSCodeCommandManager<AllCommands>();
2923
let quickPickSpy: jest.SpiedFunction<typeof window.showQuickPick>;
3024
let executeCommandSpy: jest.SpiedFunction<typeof commands.executeCommand>;
@@ -54,9 +48,16 @@ describe.skip("Variant Analysis Submission Integration", () => {
5448
await getActivatedExtension();
5549
});
5650

51+
afterAll(async () => {
52+
await commandManager.execute("codeQL.mockGitHubApiServer.unloadScenario");
53+
});
54+
5755
describe("Successful scenario", () => {
5856
beforeEach(async () => {
59-
await mockServer.loadScenario("mrva-problem-query-success");
57+
await commandManager.execute(
58+
"codeQL.mockGitHubApiServer.loadScenario",
59+
"mrva-problem-query-success",
60+
);
6061
});
6162

6263
it("opens the variant analysis view", async () => {
@@ -81,7 +82,10 @@ describe.skip("Variant Analysis Submission Integration", () => {
8182

8283
describe("Missing controller repo", () => {
8384
beforeEach(async () => {
84-
await mockServer.loadScenario("mrva-missing-controller-repo");
85+
await commandManager.execute(
86+
"codeQL.mockGitHubApiServer.loadScenario",
87+
"mrva-missing-controller-repo",
88+
);
8589
});
8690

8791
it("shows the error message", async () => {
@@ -108,7 +112,10 @@ describe.skip("Variant Analysis Submission Integration", () => {
108112

109113
describe("Submission failure", () => {
110114
beforeEach(async () => {
111-
await mockServer.loadScenario("mrva-submission-failure");
115+
await commandManager.execute(
116+
"codeQL.mockGitHubApiServer.loadScenario",
117+
"mrva-submission-failure",
118+
);
112119
});
113120

114121
it("shows the error message", async () => {

0 commit comments

Comments
 (0)