@@ -10,21 +10,11 @@ const fixtureDir = path.resolve(
10
10
11
11
suite ( 'Extension Tests' , ( ) => {
12
12
test ( 'cargo tasks are auto-detected' , async ( ) => {
13
- const projectPath = fixtureDir ;
14
- const projectUri = Uri . file ( projectPath ) ;
15
13
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' ) ,
18
16
] ;
19
17
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
-
28
18
const expected = [
29
19
{ subcommand : 'build' , group : vscode . TaskGroup . Build , cwd : projects [ 0 ] } ,
30
20
{ subcommand : 'build' , group : vscode . TaskGroup . Build , cwd : projects [ 1 ] } ,
@@ -34,22 +24,56 @@ suite('Extension Tests', () => {
34
24
{ subcommand : 'run' , group : undefined } ,
35
25
] ;
36
26
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 ) ) ;
54
54
} ) . timeout ( 0 ) ;
55
55
} ) ;
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