Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit 1365ef0

Browse files
committed
Use chai for more insightful assertion messages when testing
1 parent 965934f commit 1365ef0

File tree

3 files changed

+79
-24
lines changed

3 files changed

+79
-24
lines changed

package-lock.json

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@
5353
"vscode-languageclient": "^4.3.0"
5454
},
5555
"devDependencies": {
56+
"@types/chai": "^4.2.11",
5657
"@types/glob": "^7.1.1",
5758
"@types/mocha": "^5.2.6",
5859
"@types/node": "^10.10",
5960
"@types/vscode": "^1.31.0",
61+
"chai": "^4.2.0",
6062
"glob": "^7.1.4",
6163
"mocha": "^6.2.3",
6264
"prettier": "^1.16.4",

test/suite/extension.test.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as assert from 'assert';
1+
import { expect } from 'chai';
22
import * as path from 'path';
33
import * as vscode from 'vscode';
44
// tslint:disable-next-line: no-duplicate-imports
@@ -28,10 +28,11 @@ suite('Extension Tests', () => {
2828
const expected = [
2929
{ subcommand: 'build', group: vscode.TaskGroup.Build, cwd: projects[0] },
3030
{ subcommand: 'build', group: vscode.TaskGroup.Build, cwd: projects[1] },
31-
{ subcommand: 'check', group: vscode.TaskGroup.Build },
32-
{ subcommand: 'test', group: vscode.TaskGroup.Test },
33-
{ subcommand: 'clean', group: vscode.TaskGroup.Clean },
34-
{ subcommand: 'run', group: undefined },
31+
{ subcommand: 'check', group: vscode.TaskGroup.Build, cwd: projects[0] },
32+
{ subcommand: 'check', group: vscode.TaskGroup.Build, cwd: projects[1] },
33+
{ subcommand: 'test', group: vscode.TaskGroup.Test, cwd: projects[1] },
34+
{ subcommand: 'clean', group: vscode.TaskGroup.Clean, cwd: projects[1] },
35+
{ subcommand: 'run', group: undefined, cwd: projects[1] },
3536
];
3637

3738
const whenWorkspacesActive = projects.map(path =>
@@ -51,7 +52,7 @@ suite('Extension Tests', () => {
5152
// Wait until the first server is ready
5253
await whenWorkspacesActive[0];
5354

54-
assert(await currentTasksInclude([expected[0]]));
55+
expect(await fetchBriefTasks()).to.include.deep.members([expected[0]]);
5556

5657
// Now test for the second project
5758
await vscode.commands.executeCommand(
@@ -63,32 +64,25 @@ suite('Extension Tests', () => {
6364
);
6465
// Wait until the second server is ready
6566
await whenWorkspacesActive[1];
66-
assert(await currentTasksInclude(expected));
67+
expect(await fetchBriefTasks()).to.include.deep.members(expected);
6768
}).timeout(60000);
6869
});
6970

70-
async function currentTasksInclude(
71-
expected: Array<{
71+
/** Fetches current VSCode tasks' partial objects for ease of assertion */
72+
async function fetchBriefTasks(): Promise<
73+
Array<{
7274
subcommand: string;
7375
group: vscode.TaskGroup | undefined;
7476
cwd?: string;
75-
}>,
76-
): Promise<boolean> {
77+
}>
78+
> {
7779
const tasks = await vscode.tasks.fetchTasks();
7880

79-
return expected.every(({ subcommand, group, cwd }) =>
80-
tasks.some(
81-
task =>
82-
task.definition.type === 'cargo' &&
83-
task.definition.subcommand === subcommand &&
84-
task.group === group &&
85-
(!cwd ||
86-
cwd ===
87-
(task.execution &&
88-
task.execution.options &&
89-
task.execution.options.cwd)),
90-
),
91-
);
81+
return tasks.map(task => ({
82+
subcommand: task.definition.subcommand,
83+
group: task.group,
84+
cwd: task.execution && task.execution.options && task.execution.options.cwd,
85+
}));
9286
}
9387

9488
/**

0 commit comments

Comments
 (0)