Skip to content

Commit 8971bee

Browse files
authored
Add basic integration test for 'add db list' functionality (#1881)
1 parent 281fe56 commit 8971bee

3 files changed

Lines changed: 47 additions & 8 deletions

File tree

extensions/ql-vscode/src/databases/config/db-config-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pathExists, writeJSON, readJSON, readJSONSync } from "fs-extra";
1+
import { pathExists, outputJSON, readJSON, readJSONSync } from "fs-extra";
22
import { join } from "path";
33
import {
44
cloneDbConfig,
@@ -123,7 +123,7 @@ export class DbConfigStore extends DisposableObject {
123123
}
124124

125125
private async writeConfig(config: DbConfig): Promise<void> {
126-
await writeJSON(this.configPath, config, {
126+
await outputJSON(this.configPath, config, {
127127
spaces: 2,
128128
});
129129
}

extensions/ql-vscode/src/databases/db-module.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,25 @@ export class DbModule extends DisposableObject {
2020
}
2121

2222
public static async initialize(app: App): Promise<DbModule | undefined> {
23-
if (
24-
isCanary() &&
25-
isNewQueryRunExperienceEnabled() &&
26-
app.mode === AppMode.Development
27-
) {
23+
if (DbModule.shouldEnableModule(app.mode)) {
2824
const dbModule = new DbModule(app);
2925
app.subscriptions.push(dbModule);
3026

3127
await dbModule.initialize();
32-
3328
return dbModule;
3429
}
3530

3631
return undefined;
3732
}
3833

34+
private static shouldEnableModule(app: AppMode): boolean {
35+
if (app === AppMode.Development || app === AppMode.Test) {
36+
return true;
37+
}
38+
39+
return isCanary() && isNewQueryRunExperienceEnabled();
40+
}
41+
3942
private async initialize(): Promise<void> {
4043
void extLogger.log("Initializing database module");
4144

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { commands, extensions, window } from "vscode";
2+
3+
import { CodeQLExtensionInterface } from "../../../extension";
4+
import { readJson } from "fs-extra";
5+
import * as path from "path";
6+
import { DbConfig } from "../../../databases/config/db-config";
7+
8+
jest.setTimeout(60_000);
9+
10+
describe("Db panel UI commands", () => {
11+
let extension: CodeQLExtensionInterface | Record<string, never>;
12+
let storagePath: string;
13+
14+
beforeEach(async () => {
15+
extension = await extensions
16+
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
17+
"GitHub.vscode-codeql",
18+
)!
19+
.activate();
20+
21+
storagePath =
22+
extension.ctx.storageUri?.fsPath || extension.ctx.globalStorageUri.fsPath;
23+
});
24+
25+
it("should add new remote db list", async () => {
26+
// Add db list
27+
jest.spyOn(window, "showInputBox").mockResolvedValue("my-list-1");
28+
await commands.executeCommand("codeQLDatabasesExperimental.addNewList");
29+
30+
// Check db config
31+
const dbConfigFilePath = path.join(storagePath, "workspace-databases.json");
32+
const dbConfig: DbConfig = await readJson(dbConfigFilePath);
33+
expect(dbConfig.databases.remote.repositoryLists).toHaveLength(1);
34+
expect(dbConfig.databases.remote.repositoryLists[0].name).toBe("my-list-1");
35+
});
36+
});

0 commit comments

Comments
 (0)