1
1
import * as vscode from "vscode" ;
2
2
import { LanguageClientsManager , RobotTestItem } from "./languageclientsmanger" ;
3
- import { Mutex , sleep } from "./utils" ;
3
+ import { Mutex } from "./utils" ;
4
4
5
5
export class TestControllerManager {
6
6
private _disposables : vscode . Disposable ;
@@ -20,93 +20,15 @@ export class TestControllerManager {
20
20
"Run Tests" ,
21
21
vscode . TestRunProfileKind . Run ,
22
22
async ( request , token ) => {
23
- token . onCancellationRequested ( async ( _e ) => {
24
- console . log ( "hello canceled" ) ;
25
- } ) ;
26
- const runtest = async ( ) => {
27
- const run = this . testController . createTestRun ( request ) ;
28
-
29
- const items : vscode . TestItem [ ] = [ ] ;
30
-
31
- if ( request . include ) {
32
- request . include . forEach ( ( test ) => items . push ( test ) ) ;
33
- } else {
34
- this . testController . items . forEach ( ( test ) => items . push ( test ) ) ;
35
- }
36
-
37
- items . forEach ( ( i ) => run . enqueued ( i ) ) ;
38
-
39
- function enqueItem ( item : vscode . TestItem ) {
40
- run . enqueued ( item ) ;
41
-
42
- item . children . forEach ( ( i ) => enqueItem ( i ) ) ;
43
- }
44
-
45
- async function runItem ( item : vscode . TestItem ) {
46
- run . started ( item ) ;
47
- run . appendOutput ( `run item ${ item . id } : ${ item . label } ` ) ;
48
- run . appendOutput ( "\r\n" ) ;
49
-
50
- if ( item . children . size > 0 ) {
51
- const queue : vscode . TestItem [ ] = [ ] ;
52
-
53
- item . children . forEach ( ( i ) => queue . push ( i ) ) ;
54
-
55
- items . forEach ( ( i ) => run . enqueued ( i ) ) ;
56
-
57
- for ( const i of queue ) {
58
- await runItem ( i ) ;
59
- }
60
- } else {
61
- await sleep ( 100 ) ;
62
- }
63
-
64
- switch ( Math . floor ( Math . random ( ) * 1 ) ) {
65
- case 0 :
66
- run . passed ( item , Math . floor ( Math . random ( ) * 1000 ) ) ;
67
- break ;
68
- case 1 : {
69
- const m = new vscode . TestMessage ( "a failed test" ) ;
70
-
71
- if ( item . uri !== undefined && item . range !== undefined )
72
- m . location = new vscode . Location ( item . uri , item . range ) ;
73
-
74
- run . failed ( item , m , Math . floor ( Math . random ( ) * 1000 ) ) ;
75
- break ;
76
- }
77
- case 2 :
78
- run . skipped ( item ) ;
79
- break ;
80
- case 3 : {
81
- const m = new vscode . TestMessage ( "an errored test" ) ;
82
-
83
- if ( item . uri !== undefined && item . range !== undefined )
84
- m . location = new vscode . Location ( item . uri , item . range ) ;
85
-
86
- run . errored ( item , m , Math . floor ( Math . random ( ) * 1000 ) ) ;
87
- break ;
88
- }
89
- }
90
- }
91
-
92
- for ( const i of items ) {
93
- enqueItem ( i ) ;
94
- }
95
-
96
- for ( const i of items ) {
97
- await runItem ( i ) ;
98
- }
99
- run . end ( ) ;
100
- } ;
101
- await runtest ( ) ;
23
+ await this . runHandler ( request , token ) ;
102
24
}
103
25
) ;
104
26
105
27
this . debugProfile = this . testController . createRunProfile (
106
28
"Debug" ,
107
29
vscode . TestRunProfileKind . Debug ,
108
- ( request , _token ) => {
109
- console . log ( ` ${ request } ` ) ;
30
+ async ( request , token ) => {
31
+ await this . runHandler ( request , token ) ;
110
32
}
111
33
) ;
112
34
@@ -151,7 +73,7 @@ export class TestControllerManager {
151
73
this . testController . dispose ( ) ;
152
74
}
153
75
154
- public readonly testItems : WeakMap < vscode . WorkspaceFolder , RobotTestItem [ ] | undefined > = new Map ( ) ;
76
+ public readonly testItems = new WeakMap < vscode . WorkspaceFolder , RobotTestItem [ ] | undefined > ( ) ;
155
77
156
78
public findRobotItem ( item : vscode . TestItem ) : RobotTestItem | undefined {
157
79
if ( item . parent ) {
@@ -316,4 +238,50 @@ export class TestControllerManager {
316
238
}
317
239
} ) ;
318
240
}
241
+
242
+ private findWorkspaceForItem ( item : vscode . TestItem ) : vscode . WorkspaceFolder | undefined {
243
+ if ( item . uri !== undefined ) {
244
+ return vscode . workspace . getWorkspaceFolder ( item . uri ) ;
245
+ }
246
+
247
+ for ( const ws of vscode . workspace . workspaceFolders ?? [ ] ) {
248
+ if ( this . testItems . has ( ws ) ) {
249
+ if ( this . testItems . get ( ws ) ?. find ( ( w ) => w . id === item . id ) !== undefined ) {
250
+ return ws ;
251
+ }
252
+ }
253
+ }
254
+ return undefined ;
255
+ }
256
+
257
+ private readonly testRuns = new Map < string , vscode . TestRun > ( ) ;
258
+
259
+ private mapTestItemsToWorkspace ( items : vscode . TestItem [ ] ) : Map < vscode . WorkspaceFolder , vscode . TestItem [ ] > {
260
+ const folders = new Map < vscode . WorkspaceFolder , vscode . TestItem [ ] > ( ) ;
261
+ for ( const i of items ) {
262
+ const ws = this . findWorkspaceForItem ( i ) ;
263
+ if ( ws !== undefined ) {
264
+ if ( ! folders . has ( ws ) ) {
265
+ folders . set ( ws , [ ] ) ;
266
+ }
267
+ folders . get ( ws ) ?. push ( i ) ;
268
+ }
269
+ }
270
+ return folders ;
271
+ }
272
+
273
+ public async runHandler ( request : vscode . TestRunRequest , _token : vscode . CancellationToken ) : Promise < void > {
274
+ let includedItems : vscode . TestItem [ ] = [ ] ;
275
+
276
+ if ( request . include ) {
277
+ includedItems = request . include ;
278
+ } else {
279
+ this . testController . items . forEach ( ( test ) => includedItems . push ( test ) ) ;
280
+ }
281
+
282
+ const included = this . mapTestItemsToWorkspace ( includedItems ) ;
283
+ const excluded = this . mapTestItemsToWorkspace ( request . exclude ?? [ ] ) ;
284
+
285
+ // const run = this.testController.createTestRun(request);
286
+ }
319
287
}
0 commit comments