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

Commit 58ea299

Browse files
committed
Fix the task detection test
1 parent 0813749 commit 58ea299

File tree

1 file changed

+53
-29
lines changed

1 file changed

+53
-29
lines changed

test/suite/extension.test.ts

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,11 @@ const fixtureDir = path.resolve(
1010

1111
suite('Extension Tests', () => {
1212
test('cargo tasks are auto-detected', async () => {
13-
const projectPath = fixtureDir;
14-
const projectUri = Uri.file(projectPath);
1513
const projects = [
16-
path.join(projectPath, 'bare-lib-project'),
17-
path.join(projectPath, 'another-lib-project'),
14+
path.join(fixtureDir, 'bare-lib-project'),
15+
path.join(fixtureDir, 'another-lib-project'),
1816
];
1917

20-
await vscode.commands.executeCommand('vscode.openFolder', projectUri);
21-
await vscode.workspace.openTextDocument(
22-
Uri.file(path.join(projects[0], 'src', 'lib.rs')),
23-
);
24-
await vscode.workspace.openTextDocument(
25-
Uri.file(path.join(projects[1], 'src', 'lib.rs')),
26-
);
27-
2818
const expected = [
2919
{ subcommand: 'build', group: vscode.TaskGroup.Build, cwd: projects[0] },
3020
{ subcommand: 'build', group: vscode.TaskGroup.Build, cwd: projects[1] },
@@ -34,22 +24,56 @@ suite('Extension Tests', () => {
3424
{ subcommand: 'run', group: undefined },
3525
];
3626

37-
const tasks = await vscode.tasks.fetchTasks();
38-
39-
for (const { subcommand, group, cwd } of expected) {
40-
assert(
41-
tasks.some(
42-
task =>
43-
task.definition.type === 'cargo' &&
44-
task.definition.subcommand === subcommand &&
45-
task.group === group &&
46-
(!cwd ||
47-
cwd ===
48-
(task.execution &&
49-
task.execution.options &&
50-
task.execution.options.cwd)),
51-
),
52-
);
53-
}
27+
await vscode.commands.executeCommand('vscode.openFolder', projectUri);
28+
29+
// This makes sure that we set the focus on the opened files (which is what
30+
// actually triggers the extension for the project)
31+
await vscode.commands.executeCommand(
32+
'workbench.action.quickOpen',
33+
path.join(projects[0], 'src', 'lib.rs'),
34+
);
35+
await vscode.commands.executeCommand(
36+
'workbench.action.acceptSelectedQuickOpenItem',
37+
);
38+
await vscode.commands.executeCommand('workbench.action.keepEditor');
39+
// Unfortunately, we need to wait a bit for the extension to kick in :(
40+
// FIXME: See if we can directly import our extension and await its progress
41+
await new Promise(resolve => setTimeout(resolve, 500));
42+
assert(await currentTasksInclude([expected[0]]));
43+
44+
// Now test for the second project
45+
await vscode.commands.executeCommand(
46+
'workbench.action.quickOpen',
47+
path.join(projects[1], 'src', 'lib.rs'),
48+
);
49+
await vscode.commands.executeCommand(
50+
'workbench.action.acceptSelectedQuickOpenItem',
51+
);
52+
await new Promise(resolve => setTimeout(resolve, 500));
53+
assert(await currentTasksInclude(expected));
5454
}).timeout(0);
5555
});
56+
57+
async function currentTasksInclude(
58+
expected: Array<{
59+
subcommand: string;
60+
group: vscode.TaskGroup | undefined;
61+
cwd?: string;
62+
}>,
63+
): Promise<boolean> {
64+
const tasks = await vscode.tasks.fetchTasks();
65+
66+
return expected.every(({ subcommand, group, cwd }) =>
67+
tasks.some(
68+
task =>
69+
task.definition.type === 'cargo' &&
70+
task.definition.subcommand === subcommand &&
71+
task.group === group &&
72+
(!cwd ||
73+
cwd ===
74+
(task.execution &&
75+
task.execution.options &&
76+
task.execution.options.cwd)),
77+
),
78+
);
79+
}

0 commit comments

Comments
 (0)