11import * as vscode from "vscode" ;
22import { LanguageClientsManager , RobotTestItem } from "./languageclientsmanger" ;
3- import { Mutex , sleep } from "./utils" ;
3+ import { Mutex } from "./utils" ;
44
55export class TestControllerManager {
66 private _disposables : vscode . Disposable ;
@@ -20,93 +20,15 @@ export class TestControllerManager {
2020 "Run Tests" ,
2121 vscode . TestRunProfileKind . Run ,
2222 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 ) ;
10224 }
10325 ) ;
10426
10527 this . debugProfile = this . testController . createRunProfile (
10628 "Debug" ,
10729 vscode . TestRunProfileKind . Debug ,
108- ( request , _token ) => {
109- console . log ( ` ${ request } ` ) ;
30+ async ( request , token ) => {
31+ await this . runHandler ( request , token ) ;
11032 }
11133 ) ;
11234
@@ -151,7 +73,7 @@ export class TestControllerManager {
15173 this . testController . dispose ( ) ;
15274 }
15375
154- public readonly testItems : WeakMap < vscode . WorkspaceFolder , RobotTestItem [ ] | undefined > = new Map ( ) ;
76+ public readonly testItems = new WeakMap < vscode . WorkspaceFolder , RobotTestItem [ ] | undefined > ( ) ;
15577
15678 public findRobotItem ( item : vscode . TestItem ) : RobotTestItem | undefined {
15779 if ( item . parent ) {
@@ -316,4 +238,50 @@ export class TestControllerManager {
316238 }
317239 } ) ;
318240 }
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+ }
319287}
0 commit comments