Skip to content

Commit 1e00451

Browse files
Merge pull request #2237 from github/robertbrignull/use_app_commands_6
Convert call sites to use typed commands (part 6): createVSCodeCommandManager in tests
2 parents 0bf0127 + 1043448 commit 1e00451

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

extensions/ql-vscode/test/vscode-tests/activated-extension/databases/db-panel.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { commands, window } from "vscode";
1+
import { window } from "vscode";
22

33
import { readJson } from "fs-extra";
44
import * as path from "path";
@@ -15,11 +15,14 @@ import { createDbTreeViewItemSystemDefinedList } from "../../../../src/databases
1515
import { createRemoteSystemDefinedListDbItem } from "../../../factories/db-item-factories";
1616
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
1717
import { getActivatedExtension } from "../../global.helper";
18+
import { createVSCodeCommandManager } from "../../../../src/common/vscode/commands";
19+
import { AllCommands } from "../../../../src/common/commands";
1820

1921
jest.setTimeout(60_000);
2022

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

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

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

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

7679
jest.spyOn(window, "showInputBox").mockResolvedValue("owner1/repo1");
77-
await commands.executeCommand(
80+
await commandManager.execute(
7881
"codeQLVariantAnalysisRepositories.addNewDatabase",
7982
);
8083

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

99102
jest.spyOn(window, "showInputBox").mockResolvedValue("owner1");
100-
await commands.executeCommand(
103+
await commandManager.execute(
101104
"codeQLVariantAnalysisRepositories.addNewDatabase",
102105
);
103106

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

122-
await commands.executeCommand(
125+
await commandManager.execute(
123126
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu",
124127
treeViewItem,
125128
);

extensions/ql-vscode/test/vscode-tests/cli-integration/queries.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CancellationToken, commands, ExtensionContext, Uri } from "vscode";
1+
import { CancellationToken, ExtensionContext, Uri } from "vscode";
22
import { join, dirname } from "path";
33
import {
44
pathExistsSync,
@@ -25,6 +25,8 @@ import { QueryRunner } from "../../../src/queryRunner";
2525
import { CompletedQueryInfo } from "../../../src/query-results";
2626
import { SELECT_QUERY_NAME } from "../../../src/contextual/locationFinder";
2727
import { createMockCommandManager } from "../../__mocks__/commandsMock";
28+
import { createVSCodeCommandManager } from "../../../src/common/vscode/commands";
29+
import { AllCommands, QueryServerCommands } from "../../../src/common/commands";
2830

2931
jest.setTimeout(20_000);
3032

@@ -39,6 +41,9 @@ describeWithCodeQL()("Queries", () => {
3941
const progress = jest.fn();
4042
let token: CancellationToken;
4143
let ctx: ExtensionContext;
44+
const appCommandManager = createVSCodeCommandManager<AllCommands>();
45+
const queryServerCommandManager =
46+
createVSCodeCommandManager<QueryServerCommands>();
4247

4348
let qlpackFile: string;
4449
let qlpackLockFile: string;
@@ -176,7 +181,7 @@ describeWithCodeQL()("Queries", () => {
176181

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

192197
it("should create a quick query", async () => {
193-
await commands.executeCommand("codeQL.quickQuery");
198+
await queryServerCommandManager.execute("codeQL.quickQuery");
194199

195200
// should have created the quick query file and query pack file
196201
expect(pathExistsSync(qlFile)).toBe(true);
@@ -223,7 +228,7 @@ describeWithCodeQL()("Queries", () => {
223228
}),
224229
);
225230
writeFileSync(qlFile, "xxx");
226-
await commands.executeCommand("codeQL.quickQuery");
231+
await queryServerCommandManager.execute("codeQL.quickQuery");
227232

228233
// should not have created the quick query file because database schema hasn't changed
229234
expect(readFileSync(qlFile, "utf8")).toBe("xxx");

extensions/ql-vscode/test/vscode-tests/cli-integration/sourcemap.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import { commands, Selection, window, workspace } from "vscode";
1+
import { Selection, window, workspace } from "vscode";
22
import { join, basename } from "path";
33
import { tmpDir } from "../../../src/helpers";
44
import { readFile, writeFile, ensureDir, copy } from "fs-extra";
5+
import { createVSCodeCommandManager } from "../../../src/common/vscode/commands";
6+
import { AllCommands } from "../../../src/common/commands";
57

68
jest.setTimeout(20_000);
79

810
/**
911
* Integration tests for queries
1012
*/
1113
describe("SourceMap", () => {
14+
const commandManager = createVSCodeCommandManager<AllCommands>();
15+
1216
it("should jump to QL code", async () => {
1317
const root = workspace.workspaceFolders![0].uri.fsPath;
1418
const srcFiles = {
@@ -32,7 +36,7 @@ describe("SourceMap", () => {
3236
expect(summaryDocument.languageId).toBe("ql-summary");
3337
const summaryEditor = await window.showTextDocument(summaryDocument);
3438
summaryEditor.selection = new Selection(356, 10, 356, 10);
35-
await commands.executeCommand("codeQL.gotoQL");
39+
await commandManager.execute("codeQL.gotoQL");
3640

3741
const newEditor = window.activeTextEditor;
3842
expect(newEditor).toBeDefined();

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { MockGitHubApiServer } from "../../../../src/mocks/mock-gh-api-server";
1212
import { mockedQuickPickItem } from "../../utils/mocking.helpers";
1313
import { setRemoteControllerRepo } from "../../../../src/config";
1414
import { getActivatedExtension } from "../../global.helper";
15+
import { createVSCodeCommandManager } from "../../../../src/common/vscode/commands";
16+
import { AllCommands } from "../../../../src/common/commands";
1517

1618
jest.setTimeout(30_000);
1719

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

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

71-
await commands.executeCommand("codeQL.runVariantAnalysis");
74+
await commandManager.execute("codeQL.runVariantAnalysis");
7275

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

88-
await commands.executeCommand("codeQL.runVariantAnalysis");
91+
await commandManager.execute("codeQL.runVariantAnalysis");
8992

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

110-
await commands.executeCommand("codeQL.runVariantAnalysis");
113+
await commandManager.execute("codeQL.runVariantAnalysis");
111114

112115
expect(showErrorMessageSpy).toHaveBeenCalledWith(
113116
expect.stringContaining(

0 commit comments

Comments
 (0)