Skip to content

Commit a27f58d

Browse files
Convert tests that call real commands to use createVSCodeCommandManager
1 parent 1e4672b commit a27f58d

4 files changed

Lines changed: 24 additions & 15 deletions

File tree

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

Lines changed: 8 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,13 @@ 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";
1819

1920
jest.setTimeout(60_000);
2021

2122
describe("Db panel UI commands", () => {
2223
let storagePath: string;
24+
const commandManager = createVSCodeCommandManager();
2325

2426
beforeEach(async () => {
2527
const extension = await getActivatedExtension();
@@ -31,7 +33,7 @@ describe("Db panel UI commands", () => {
3133
it("should add new remote db list", async () => {
3234
// Add db list
3335
jest.spyOn(window, "showInputBox").mockResolvedValue("my-list-1");
34-
await commands.executeCommand(
36+
await commandManager.execute(
3537
"codeQLVariantAnalysisRepositories.addNewList",
3638
);
3739

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

@@ -74,7 +76,7 @@ describe("Db panel UI commands", () => {
7476
} as RemoteDatabaseQuickPickItem);
7577

7678
jest.spyOn(window, "showInputBox").mockResolvedValue("owner1/repo1");
77-
await commands.executeCommand(
79+
await commandManager.execute(
7880
"codeQLVariantAnalysisRepositories.addNewDatabase",
7981
);
8082

@@ -97,7 +99,7 @@ describe("Db panel UI commands", () => {
9799
} as RemoteDatabaseQuickPickItem);
98100

99101
jest.spyOn(window, "showInputBox").mockResolvedValue("owner1");
100-
await commands.executeCommand(
102+
await commandManager.execute(
101103
"codeQLVariantAnalysisRepositories.addNewDatabase",
102104
);
103105

@@ -119,7 +121,7 @@ describe("Db panel UI commands", () => {
119121
"tooltip",
120122
);
121123

122-
await commands.executeCommand(
124+
await commandManager.execute(
123125
"codeQLVariantAnalysisRepositories.setSelectedItemContextMenu",
124126
treeViewItem,
125127
);

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

Lines changed: 6 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,7 @@ 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";
2829

2930
jest.setTimeout(20_000);
3031

@@ -39,6 +40,7 @@ describeWithCodeQL()("Queries", () => {
3940
const progress = jest.fn();
4041
let token: CancellationToken;
4142
let ctx: ExtensionContext;
43+
const commandManager = createVSCodeCommandManager();
4244

4345
let qlpackFile: string;
4446
let qlpackLockFile: string;
@@ -176,7 +178,7 @@ describeWithCodeQL()("Queries", () => {
176178

177179
// Asserts a fix for bug https://github.com/github/vscode-codeql/issues/733
178180
it("should restart the database and run a query", async () => {
179-
await commands.executeCommand("codeQL.restartQueryServer");
181+
await commandManager.execute("codeQL.restartQueryServer");
180182
const queryPath = join(__dirname, "data", "simple-query.ql");
181183
const result = await qs.compileAndRunQueryAgainstDatabase(
182184
dbItem,
@@ -190,7 +192,7 @@ describeWithCodeQL()("Queries", () => {
190192
});
191193

192194
it("should create a quick query", async () => {
193-
await commands.executeCommand("codeQL.quickQuery");
195+
await commandManager.execute("codeQL.quickQuery");
194196

195197
// should have created the quick query file and query pack file
196198
expect(pathExistsSync(qlFile)).toBe(true);
@@ -223,7 +225,7 @@ describeWithCodeQL()("Queries", () => {
223225
}),
224226
);
225227
writeFileSync(qlFile, "xxx");
226-
await commands.executeCommand("codeQL.quickQuery");
228+
await commandManager.execute("codeQL.quickQuery");
227229

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

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
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";
56

67
jest.setTimeout(20_000);
78

89
/**
910
* Integration tests for queries
1011
*/
1112
describe("SourceMap", () => {
13+
const commandManager = createVSCodeCommandManager();
14+
1215
it("should jump to QL code", async () => {
1316
const root = workspace.workspaceFolders![0].uri.fsPath;
1417
const srcFiles = {
@@ -32,7 +35,7 @@ describe("SourceMap", () => {
3235
expect(summaryDocument.languageId).toBe("ql-summary");
3336
const summaryEditor = await window.showTextDocument(summaryDocument);
3437
summaryEditor.selection = new Selection(356, 10, 356, 10);
35-
await commands.executeCommand("codeQL.gotoQL");
38+
await commandManager.execute("codeQL.gotoQL");
3639

3740
const newEditor = window.activeTextEditor;
3841
expect(newEditor).toBeDefined();

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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";
1516

1617
jest.setTimeout(30_000);
1718

@@ -29,6 +30,7 @@ async function showQlDocument(name: string): Promise<TextDocument> {
2930
}
3031

3132
describe("Variant Analysis Submission Integration", () => {
33+
const commandManager = createVSCodeCommandManager();
3234
let quickPickSpy: jest.SpiedFunction<typeof window.showQuickPick>;
3335
let executeCommandSpy: jest.SpiedFunction<typeof commands.executeCommand>;
3436
let showErrorMessageSpy: jest.SpiedFunction<typeof window.showErrorMessage>;
@@ -68,7 +70,7 @@ describe("Variant Analysis Submission Integration", () => {
6870
// Select target language for your query
6971
quickPickSpy.mockResolvedValueOnce(mockedQuickPickItem("javascript"));
7072

71-
await commands.executeCommand("codeQL.runVariantAnalysis");
73+
await commandManager.execute("codeQL.runVariantAnalysis");
7274

7375
expect(executeCommandSpy).toHaveBeenCalledWith(
7476
"codeQL.openVariantAnalysisView",
@@ -85,7 +87,7 @@ describe("Variant Analysis Submission Integration", () => {
8587
it("shows the error message", async () => {
8688
await showQlDocument("query.ql");
8789

88-
await commands.executeCommand("codeQL.runVariantAnalysis");
90+
await commandManager.execute("codeQL.runVariantAnalysis");
8991

9092
expect(showErrorMessageSpy).toHaveBeenCalledWith(
9193
expect.stringContaining(
@@ -107,7 +109,7 @@ describe("Variant Analysis Submission Integration", () => {
107109
// Select target language for your query
108110
quickPickSpy.mockResolvedValueOnce(mockedQuickPickItem("javascript"));
109111

110-
await commands.executeCommand("codeQL.runVariantAnalysis");
112+
await commandManager.execute("codeQL.runVariantAnalysis");
111113

112114
expect(showErrorMessageSpy).toHaveBeenCalledWith(
113115
expect.stringContaining(

0 commit comments

Comments
 (0)