Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { commands, window } from "vscode";
import { window } from "vscode";

import { readJson } from "fs-extra";
import * as path from "path";
Expand All @@ -15,11 +15,14 @@ import { createDbTreeViewItemSystemDefinedList } from "../../../../src/databases
import { createRemoteSystemDefinedListDbItem } from "../../../factories/db-item-factories";
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
import { getActivatedExtension } from "../../global.helper";
import { createVSCodeCommandManager } from "../../../../src/common/vscode/commands";
import { AllCommands } from "../../../../src/common/commands";

jest.setTimeout(60_000);

describe("Db panel UI commands", () => {
let storagePath: string;
const commandManager = createVSCodeCommandManager<AllCommands>();

beforeEach(async () => {
const extension = await getActivatedExtension();
Expand All @@ -31,7 +34,7 @@ describe("Db panel UI commands", () => {
it("should add new remote db list", async () => {
// Add db list
jest.spyOn(window, "showInputBox").mockResolvedValue("my-list-1");
await commands.executeCommand(
await commandManager.execute(
"codeQLVariantAnalysisRepositories.addNewList",
);

Expand All @@ -53,7 +56,7 @@ describe("Db panel UI commands", () => {
kind: DbListKind.Local,
} as AddListQuickPickItem);
jest.spyOn(window, "showInputBox").mockResolvedValue("my-list-1");
await commands.executeCommand(
await commandManager.execute(
"codeQLVariantAnalysisRepositories.addNewList",
);

Expand All @@ -74,7 +77,7 @@ describe("Db panel UI commands", () => {
} as RemoteDatabaseQuickPickItem);

jest.spyOn(window, "showInputBox").mockResolvedValue("owner1/repo1");
await commands.executeCommand(
await commandManager.execute(
"codeQLVariantAnalysisRepositories.addNewDatabase",
);

Expand All @@ -97,7 +100,7 @@ describe("Db panel UI commands", () => {
} as RemoteDatabaseQuickPickItem);

jest.spyOn(window, "showInputBox").mockResolvedValue("owner1");
await commands.executeCommand(
await commandManager.execute(
"codeQLVariantAnalysisRepositories.addNewDatabase",
);

Expand All @@ -119,7 +122,7 @@ describe("Db panel UI commands", () => {
"tooltip",
);

await commands.executeCommand(
await commandManager.execute(
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu",
treeViewItem,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CancellationToken, commands, ExtensionContext, Uri } from "vscode";
import { CancellationToken, ExtensionContext, Uri } from "vscode";
import { join, dirname } from "path";
import {
pathExistsSync,
Expand All @@ -25,6 +25,8 @@ import { QueryRunner } from "../../../src/queryRunner";
import { CompletedQueryInfo } from "../../../src/query-results";
import { SELECT_QUERY_NAME } from "../../../src/contextual/locationFinder";
import { createMockCommandManager } from "../../__mocks__/commandsMock";
import { createVSCodeCommandManager } from "../../../src/common/vscode/commands";
import { AllCommands, QueryServerCommands } from "../../../src/common/commands";

jest.setTimeout(20_000);

Expand All @@ -39,6 +41,9 @@ describeWithCodeQL()("Queries", () => {
const progress = jest.fn();
let token: CancellationToken;
let ctx: ExtensionContext;
const appCommandManager = createVSCodeCommandManager<AllCommands>();
const queryServerCommandManager =
createVSCodeCommandManager<QueryServerCommands>();

let qlpackFile: string;
let qlpackLockFile: string;
Expand Down Expand Up @@ -176,7 +181,7 @@ describeWithCodeQL()("Queries", () => {

// Asserts a fix for bug https://github.com/github/vscode-codeql/issues/733
it("should restart the database and run a query", async () => {
await commands.executeCommand("codeQL.restartQueryServer");
await appCommandManager.execute("codeQL.restartQueryServer");
const queryPath = join(__dirname, "data", "simple-query.ql");
const result = await qs.compileAndRunQueryAgainstDatabase(
dbItem,
Expand All @@ -190,7 +195,7 @@ describeWithCodeQL()("Queries", () => {
});

it("should create a quick query", async () => {
await commands.executeCommand("codeQL.quickQuery");
await queryServerCommandManager.execute("codeQL.quickQuery");

// should have created the quick query file and query pack file
expect(pathExistsSync(qlFile)).toBe(true);
Expand Down Expand Up @@ -223,7 +228,7 @@ describeWithCodeQL()("Queries", () => {
}),
);
writeFileSync(qlFile, "xxx");
await commands.executeCommand("codeQL.quickQuery");
await queryServerCommandManager.execute("codeQL.quickQuery");

// should not have created the quick query file because database schema hasn't changed
expect(readFileSync(qlFile, "utf8")).toBe("xxx");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { commands, Selection, window, workspace } from "vscode";
import { Selection, window, workspace } from "vscode";
import { join, basename } from "path";
import { tmpDir } from "../../../src/helpers";
import { readFile, writeFile, ensureDir, copy } from "fs-extra";
import { createVSCodeCommandManager } from "../../../src/common/vscode/commands";
import { AllCommands } from "../../../src/common/commands";

jest.setTimeout(20_000);

/**
* Integration tests for queries
*/
describe("SourceMap", () => {
const commandManager = createVSCodeCommandManager<AllCommands>();

it("should jump to QL code", async () => {
const root = workspace.workspaceFolders![0].uri.fsPath;
const srcFiles = {
Expand All @@ -32,7 +36,7 @@ describe("SourceMap", () => {
expect(summaryDocument.languageId).toBe("ql-summary");
const summaryEditor = await window.showTextDocument(summaryDocument);
summaryEditor.selection = new Selection(356, 10, 356, 10);
await commands.executeCommand("codeQL.gotoQL");
await commandManager.execute("codeQL.gotoQL");

const newEditor = window.activeTextEditor;
expect(newEditor).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { MockGitHubApiServer } from "../../../../src/mocks/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 { AllCommands } from "../../../../src/common/commands";

jest.setTimeout(30_000);

Expand All @@ -29,6 +31,7 @@ async function showQlDocument(name: string): Promise<TextDocument> {
}

describe("Variant Analysis Submission Integration", () => {
const commandManager = createVSCodeCommandManager<AllCommands>();
let quickPickSpy: jest.SpiedFunction<typeof window.showQuickPick>;
let executeCommandSpy: jest.SpiedFunction<typeof commands.executeCommand>;
let showErrorMessageSpy: jest.SpiedFunction<typeof window.showErrorMessage>;
Expand Down Expand Up @@ -68,7 +71,7 @@ describe("Variant Analysis Submission Integration", () => {
// Select target language for your query
quickPickSpy.mockResolvedValueOnce(mockedQuickPickItem("javascript"));

await commands.executeCommand("codeQL.runVariantAnalysis");
await commandManager.execute("codeQL.runVariantAnalysis");

expect(executeCommandSpy).toHaveBeenCalledWith(
"codeQL.openVariantAnalysisView",
Expand All @@ -85,7 +88,7 @@ describe("Variant Analysis Submission Integration", () => {
it("shows the error message", async () => {
await showQlDocument("query.ql");

await commands.executeCommand("codeQL.runVariantAnalysis");
await commandManager.execute("codeQL.runVariantAnalysis");

expect(showErrorMessageSpy).toHaveBeenCalledWith(
expect.stringContaining(
Expand All @@ -107,7 +110,7 @@ describe("Variant Analysis Submission Integration", () => {
// Select target language for your query
quickPickSpy.mockResolvedValueOnce(mockedQuickPickItem("javascript"));

await commands.executeCommand("codeQL.runVariantAnalysis");
await commandManager.execute("codeQL.runVariantAnalysis");

expect(showErrorMessageSpy).toHaveBeenCalledWith(
expect.stringContaining(
Expand Down