Merge pull request #2237 from github/robertbrignull/use_app_commands_6

Convert call sites to use typed commands (part 6): createVSCodeCommandManager in tests
This commit is contained in:
Robert
2023-03-30 10:30:26 +01:00
committed by GitHub
4 changed files with 30 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
import { commands, window } from "vscode";
import { window } from "vscode";
import { readJson } from "fs-extra";
import * as path from "path";
@@ -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();
@@ -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",
);
@@ -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",
);
@@ -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",
);
@@ -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",
);
@@ -119,7 +122,7 @@ describe("Db panel UI commands", () => {
"tooltip",
);
await commands.executeCommand(
await commandManager.execute(
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu",
treeViewItem,
);

View File

@@ -1,4 +1,4 @@
import { CancellationToken, commands, ExtensionContext, Uri } from "vscode";
import { CancellationToken, ExtensionContext, Uri } from "vscode";
import { join, dirname } from "path";
import {
pathExistsSync,
@@ -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);
@@ -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;
@@ -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,
@@ -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);
@@ -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");

View File

@@ -1,7 +1,9 @@
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);
@@ -9,6 +11,8 @@ 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 = {
@@ -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();

View File

@@ -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);
@@ -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>;
@@ -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",
@@ -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(
@@ -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(