Skip to content

Commit 91ca948

Browse files
authored
Migrate minimal-workspace integration tests to Jest (#1786)
1 parent c31635f commit 91ca948

11 files changed

Lines changed: 295 additions & 345 deletions

File tree

extensions/ql-vscode/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ module.exports = {
99
"<rootDir>/src/view",
1010
"<rootDir>/test",
1111
"<rootDir>/out/vscode-tests/no-workspace",
12+
"<rootDir>/out/vscode-tests/minimal-workspace",
1213
],
1314
};

extensions/ql-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@
12741274
"test:view": "jest --projects src/view",
12751275
"integration": "npm-run-all integration:*",
12761276
"integration:no-workspace": "jest --projects out/vscode-tests/no-workspace",
1277-
"integration:minimal-workspace": "node ./out/vscode-tests/run-integration-tests.js minimal-workspace",
1277+
"integration:minimal-workspace": "jest --projects out/vscode-tests/minimal-workspace",
12781278
"cli-integration": "node ./out/vscode-tests/run-integration-tests.js cli-integration",
12791279
"update-vscode": "node ./node_modules/vscode/bin/install",
12801280
"format": "prettier --write **/*.{ts,tsx} && eslint . --ext .ts,.tsx --fix",

extensions/ql-vscode/src/vscode-tests/minimal-workspace/activation.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1-
import * as assert from "assert";
21
import * as path from "path";
32
import * as vscode from "vscode";
43
import * as determiningSelectedQueryTest from "./determining-selected-query-test";
54

6-
describe("launching with a minimal workspace", async () => {
5+
// Temporary until Mocha is fully removed. This is necessary for passing timeouts to `it`.
6+
declare let it: jest.It;
7+
8+
describe("launching with a minimal workspace", () => {
79
const ext = vscode.extensions.getExtension("GitHub.vscode-codeql");
810
it("should install the extension", () => {
9-
assert(ext);
11+
expect(ext).toBeDefined();
1012
});
1113

1214
// Note, this test will only pass in pristine workspaces. This means that when run locally and you
1315
// reuse an existing workspace that starts with an open ql file, this test will fail. There is
1416
// no need to make any changes since this will still pass on CI.
1517
it("should not activate the extension at first", () => {
16-
assert(ext!.isActive === false);
18+
expect(ext!.isActive).toEqual(false);
1719
});
1820

19-
it("should activate the extension when a .ql file is opened", async function () {
20-
this.timeout(60000);
21+
it("should activate the extension when a .ql file is opened", async () => {
2122
await delay();
2223

2324
const folders = vscode.workspace.workspaceFolders;
24-
assert(folders && folders.length === 1);
25+
expect(folders?.length).toEqual(1);
2526
const folderPath = folders![0].uri.fsPath;
2627
const documentPath = path.resolve(folderPath, "query.ql");
2728
const document = await vscode.workspace.openTextDocument(documentPath);
28-
assert(document.languageId === "ql");
29+
expect(document.languageId).toEqual("ql");
2930
// Delay slightly so that the extension has time to activate.
3031
await delay();
31-
assert(ext!.isActive);
32-
});
32+
expect(ext!.isActive).toBeTruthy();
33+
}, 60_000);
3334

3435
async function delay() {
3536
await new Promise((resolve) => setTimeout(resolve, 4000));

extensions/ql-vscode/src/vscode-tests/minimal-workspace/config.test.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
1-
import * as Sinon from "sinon";
2-
import { expect } from "chai";
31
import { workspace } from "vscode";
42

53
import {
64
CliConfigListener,
5+
ConfigListener,
76
QueryHistoryConfigListener,
87
QueryServerConfigListener,
98
} from "../../config";
109

11-
describe("config listeners", function () {
12-
// Because we are adding some extra waiting, need to bump the test timeouts.
13-
this.timeout(5000);
14-
15-
let sandbox: Sinon.SinonSandbox;
16-
beforeEach(() => {
17-
sandbox = Sinon.createSandbox();
18-
});
19-
20-
afterEach(() => {
21-
sandbox.restore();
22-
});
23-
10+
describe("config listeners", () => {
2411
interface TestConfig<T> {
25-
clazz: new () => unknown;
12+
clazz: new () => ConfigListener;
2613
settings: {
2714
name: string;
2815
property: string;
@@ -95,23 +82,14 @@ describe("config listeners", function () {
9582

9683
testConfig.forEach((config) => {
9784
describe(config.clazz.name, () => {
98-
let listener: any;
99-
let spy: Sinon.SinonSpy;
100-
beforeEach(() => {
101-
listener = new config.clazz();
102-
spy = Sinon.spy();
103-
listener.onDidChangeConfiguration(spy);
104-
});
105-
10685
config.settings.forEach((setting) => {
107-
let origValue: any;
86+
let origValue: string | number | boolean | undefined;
10887
beforeEach(async () => {
10988
origValue = workspace.getConfiguration().get(setting.name);
11089
await workspace
11190
.getConfiguration()
11291
.update(setting.name, setting.values[0]);
11392
await wait();
114-
spy.resetHistory();
11593
});
11694

11795
afterEach(async () => {
@@ -120,12 +98,17 @@ describe("config listeners", function () {
12098
});
12199

122100
it(`should listen for changes to '${setting.name}'`, async () => {
101+
const listener = new config.clazz();
102+
const onDidChangeConfiguration = jest.fn();
103+
listener.onDidChangeConfiguration(onDidChangeConfiguration);
104+
123105
await workspace
124106
.getConfiguration()
125107
.update(setting.name, setting.values[1]);
126108
await wait();
127-
expect(listener[setting.property]).to.eq(setting.values[1]);
128-
expect(spy).to.have.been.calledOnce;
109+
const newValue = listener[setting.property as keyof typeof listener];
110+
expect(newValue).toEqual(setting.values[1]);
111+
expect(onDidChangeConfiguration).toHaveBeenCalledTimes(1);
129112
});
130113
});
131114
});

0 commit comments

Comments
 (0)