-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathglobal.helper.ts
More file actions
72 lines (63 loc) · 2.14 KB
/
global.helper.ts
File metadata and controls
72 lines (63 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { join } from "path";
import { realpathSync } from "fs-extra";
import { extensions, Uri } from "vscode";
import {
DatabaseItem,
DatabaseManager,
} from "../../src/databases/local-databases";
import { CodeQLCliServer } from "../../src/codeql-cli/cli";
import { CodeQLExtensionInterface } from "../../src/extension";
import { importArchiveDatabase } from "../../src/databases/database-fetcher";
import { createMockCommandManager } from "../__mocks__/commandsMock";
// This file contains helpers shared between tests that work with an activated extension.
export const DB_URL =
"https://github.com/github/vscode-codeql/files/5586722/simple-db.zip";
// We need to resolve the path, but the final three segments won't exist until later, so we only resolve the
// first portion of the path.
export const dbLoc = join(
realpathSync(join(__dirname, "../../../")),
"build/tests/db.zip",
);
export let storagePath: string;
/**
* Removes any existing databases from the database panel, and loads the test database.
*/
export async function ensureTestDatabase(
databaseManager: DatabaseManager,
cli: CodeQLCliServer,
): Promise<DatabaseItem> {
// Add a database, but make sure the database manager is empty first
await cleanDatabases(databaseManager);
const uri = Uri.file(dbLoc);
const maybeDbItem = await importArchiveDatabase(
createMockCommandManager(),
uri.toString(true),
databaseManager,
storagePath,
(_p) => {
/**/
},
cli,
);
if (!maybeDbItem) {
throw new Error("Could not import database");
}
return maybeDbItem;
}
export function setStoragePath(path: string) {
storagePath = path;
}
export async function getActivatedExtension(): Promise<CodeQLExtensionInterface> {
const extension = await extensions
.getExtension<CodeQLExtensionInterface | undefined>("GitHub.vscode-codeql")
?.activate();
if (extension === undefined) {
throw new Error(
"Unable to active CodeQL extension. Make sure cli is downloaded and installed properly.",
);
}
return extension;
}
export async function cleanDatabases(databaseManager: DatabaseManager) {
await databaseManager.removeAllDatabases();
}