Skip to content

Commit

Permalink
Merge pull request #3800 from github/koesie10/fix-variant-analysis-su…
Browse files Browse the repository at this point in the history
…bmission-integration-tests

Fix and re-enable variant analysis submission integration tests
  • Loading branch information
koesie10 authored Nov 12, 2024
2 parents b44c602 + 11bc465 commit 71cd892
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 29 deletions.
4 changes: 3 additions & 1 deletion extensions/ql-vscode/src/common/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ export type MockGitHubApiServerCommands = {
"codeQL.mockGitHubApiServer.startRecording": () => Promise<void>;
"codeQL.mockGitHubApiServer.saveScenario": () => Promise<void>;
"codeQL.mockGitHubApiServer.cancelRecording": () => Promise<void>;
"codeQL.mockGitHubApiServer.loadScenario": () => Promise<void>;
"codeQL.mockGitHubApiServer.loadScenario": (
scenario?: string,
) => Promise<void>;
"codeQL.mockGitHubApiServer.unloadScenario": () => Promise<void>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,33 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
);
}

public async loadScenario(): Promise<void> {
public async loadScenario(scenario?: string): Promise<void> {
const scenariosPath = await this.getScenariosPath();
if (!scenariosPath) {
return;
}

const scenarioNames = await this.server.getScenarioNames(scenariosPath);
const scenarioQuickPickItems = scenarioNames.map((s) => ({ label: s }));
const quickPickOptions = {
placeHolder: "Select a scenario to load",
};
const selectedScenario = await window.showQuickPick<QuickPickItem>(
scenarioQuickPickItems,
quickPickOptions,
);
if (!selectedScenario) {
return;
let scenarioName = scenario;
if (!scenarioName) {
const scenarioNames = await this.server.getScenarioNames(scenariosPath);
const scenarioQuickPickItems = scenarioNames.map((s) => ({ label: s }));
const quickPickOptions = {
placeHolder: "Select a scenario to load",
};
const selectedScenario = await window.showQuickPick<QuickPickItem>(
scenarioQuickPickItems,
quickPickOptions,
);
if (!selectedScenario) {
return;
}

scenarioName = selectedScenario.label;
}

const scenarioName = selectedScenario.label;
if (!this.server.isListening && this.app.mode === AppMode.Test) {
await this.startServer();
}

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

Expand All @@ -94,20 +101,24 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
true,
);

await window.showInformationMessage(`Loaded scenario '${scenarioName}'`);
void window.showInformationMessage(`Loaded scenario '${scenarioName}'`);
}

public async unloadScenario(): Promise<void> {
if (!this.server.isScenarioLoaded) {
await window.showInformationMessage("No scenario currently loaded");
void window.showInformationMessage("No scenario currently loaded");
} else {
await this.server.unloadScenario();
await this.app.commands.execute(
"setContext",
"codeQL.mockGitHubApiServer.scenarioLoaded",
false,
);
await window.showInformationMessage("Unloaded scenario");
void window.showInformationMessage("Unloaded scenario");
}

if (this.server.isListening && this.app.mode === AppMode.Test) {
await this.stopServer();
}
}

Expand Down Expand Up @@ -139,7 +150,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
true,
);

await window.showInformationMessage(
void window.showInformationMessage(
'Recording scenario. To save the scenario, use the "CodeQL Mock GitHub API Server: Save Scenario" command.',
);
}
Expand Down Expand Up @@ -221,7 +232,10 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
return scenariosPath;
}

if (this.app.mode === AppMode.Development) {
if (
this.app.mode === AppMode.Development ||
this.app.mode === AppMode.Test
) {
const developmentScenariosPath = path.join(
this.app.extensionPath,
"src/common/mock-gh-api/scenarios",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ import { resolve } from "path";
import type { TextDocument } from "vscode";
import { authentication, commands, window, workspace } from "vscode";

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

const mockServer = new MockGitHubApiServer();
beforeAll(() => mockServer.startServer("bypass"));
afterEach(() => mockServer.unloadScenario());
afterAll(() => mockServer.stopServer());

async function showQlDocument(name: string): Promise<TextDocument> {
const folderPath = workspace.workspaceFolders![0].uri.fsPath;
const documentPath = resolve(folderPath, name);
Expand All @@ -24,7 +18,7 @@ async function showQlDocument(name: string): Promise<TextDocument> {
}

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

afterAll(async () => {
await commandManager.execute("codeQL.mockGitHubApiServer.unloadScenario");
});

describe("Successful scenario", () => {
beforeEach(async () => {
await mockServer.loadScenario("mrva-problem-query-success");
await commandManager.execute(
"codeQL.mockGitHubApiServer.loadScenario",
"mrva-problem-query-success",
);
});

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

describe("Missing controller repo", () => {
beforeEach(async () => {
await mockServer.loadScenario("mrva-missing-controller-repo");
await commandManager.execute(
"codeQL.mockGitHubApiServer.loadScenario",
"mrva-missing-controller-repo",
);
});

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

describe("Submission failure", () => {
beforeEach(async () => {
await mockServer.loadScenario("mrva-submission-failure");
await commandManager.execute(
"codeQL.mockGitHubApiServer.loadScenario",
"mrva-submission-failure",
);
});

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

0 comments on commit 71cd892

Please sign in to comment.