-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathactivation.test.ts
More file actions
46 lines (41 loc) · 1.68 KB
/
activation.test.ts
File metadata and controls
46 lines (41 loc) · 1.68 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
import { resolve } from "path";
import type { Extension } from "vscode";
import { extensions, workspace } from "vscode";
import { run } from "./local-queries/determining-selected-query-test";
describe("launching with a minimal workspace", () => {
const ext = extensions.getExtension("GitHub.vscode-codeql");
it("should install the extension", () => {
expect(ext).toBeDefined();
});
// Note, this test will only pass in pristine workspaces. This means that when run locally and you
// reuse an existing workspace that starts with an open ql file, this test will fail. There is
// no need to make any changes since this will still pass on CI.
it("should not activate the extension at first", () => {
expect(ext!.isActive).toEqual(false);
});
it("should activate the extension when a .ql file is opened", async () => {
const folders = workspace.workspaceFolders;
expect(folders?.length).toEqual(1);
const folderPath = folders![0].uri.fsPath;
const documentPath = resolve(folderPath, "query.ql");
const document = await workspace.openTextDocument(documentPath);
expect(document.languageId).toEqual("ql");
// Wait for the extension to activate, polling with a timeout.
await waitForActivation(ext!, 30_000);
expect(ext!.isActive).toBeTruthy();
}, 60_000);
async function waitForActivation(
extension: Extension<any>,
timeoutMs: number,
): Promise<void> {
const pollIntervalMs = 100;
const maxAttempts = Math.ceil(timeoutMs / pollIntervalMs);
for (let i = 0; i < maxAttempts; i++) {
if (extension.isActive) {
return;
}
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
}
}
});
run();