1818 */
1919'use strict' ;
2020
21- import { commands , debug , tests , workspace , CancellationToken , TestController , TestItem , TestRunProfileKind , TestRunRequest , Uri , TestRun , TestMessage , Location , Position , MarkdownString , TestRunProfile } from "vscode" ;
21+ import { commands , debug , tests , workspace , CancellationToken , TestController , TestItem , TestRunProfileKind , TestRunRequest , Uri , TestRun , TestMessage , Location , Position , MarkdownString , TestRunProfile , CancellationTokenSource } from "vscode" ;
2222import * as path from 'path' ;
2323import { asRange , TestCase , TestSuite } from "./protocol" ;
2424import { COMMAND_PREFIX , listeners , TEST_PROGRESS_EVENT } from "./extension" ;
@@ -33,6 +33,7 @@ export class NbTestAdapter {
3333 private itemsToRun : Set < TestItem > | undefined ;
3434 private started : boolean = false ;
3535 private suiteStates : Map < TestItem , SuiteState > ;
36+ private parallelRunProfile : TestRunProfile | undefined ;
3637
3738 constructor ( ) {
3839 this . testController = tests . createTestController ( 'apacheNetBeansController' , 'Apache NetBeans' ) ;
@@ -46,7 +47,15 @@ export class NbTestAdapter {
4647
4748 public registerRunInParallelProfile ( projects : string [ ] ) {
4849 const runHandler = ( request : TestRunRequest , cancellation : CancellationToken ) => this . run ( request , cancellation , true , projects ) ;
49- this . testController . createRunProfile ( "Run Tests In Parallel" , TestRunProfileKind . Run , runHandler , true ) ;
50+ this . parallelRunProfile = this . testController . createRunProfile ( "Run Tests In Parallel" , TestRunProfileKind . Run , runHandler , true ) ;
51+ this . testController . items . replace ( [ ] ) ;
52+ this . load ( ) ;
53+ }
54+
55+ public runTestsWithParallelParallel ( projects ?: string [ ] ) {
56+ if ( this . parallelRunProfile ) {
57+ this . run ( new TestRunRequest ( undefined , undefined , this . parallelRunProfile ) , new CancellationTokenSource ( ) . token , true , projects ) ;
58+ }
5059 }
5160
5261 async load ( ) : Promise < void > {
@@ -198,7 +207,7 @@ export class NbTestAdapter {
198207 }
199208
200209 testProgress ( suite : TestSuite ) : void {
201- const currentModule = this . testController . items . get ( this . getModuleName ( suite ) ) ;
210+ const currentModule = this . testController . items . get ( suite . moduleName || "" ) ;
202211 const currentSuite = currentModule ?. children . get ( suite . name ) ;
203212
204213 switch ( suite . state ) {
@@ -287,10 +296,11 @@ export class NbTestAdapter {
287296 }
288297
289298 updateTests ( suite : TestSuite , testExecution ?: boolean ) : void {
290- const moduleName = this . getModuleName ( suite ) ;
299+ const moduleName = suite . moduleName || "" ;
291300 let currentModule = this . testController . items . get ( moduleName ) ;
292301 if ( ! currentModule ) {
293- currentModule = this . testController . createTestItem ( moduleName , this . getNameWithIcon ( moduleName , 'module' ) , this . getModulePath ( suite ) ) ;
302+ const parsedName = this . parseModuleName ( moduleName ) ;
303+ currentModule = this . testController . createTestItem ( moduleName , this . getNameWithIcon ( parsedName , 'module' ) , this . getModulePath ( suite ) ) ;
294304 this . testController . items . add ( currentModule ) ;
295305 }
296306
@@ -360,11 +370,19 @@ export class NbTestAdapter {
360370 currentModule . children . replace ( suiteChildren ) ;
361371 }
362372 }
363-
364- getModuleName ( suite : TestSuite ) : string {
365- return suite . moduleName ?. replace ( ":" , "-" ) || "" ;
373+
374+ parseModuleName ( moduleName : string ) : string {
375+ if ( ! this . parallelRunProfile ) {
376+ return moduleName . replace ( ":" , "-" ) ;
377+ }
378+ const index = moduleName . indexOf ( ":" ) ;
379+ if ( index !== - 1 ) {
380+ return moduleName . slice ( index + 1 ) ;
381+ }
382+ const parts = moduleName . split ( "-" ) ;
383+ return parts [ parts . length - 1 ] ;
366384 }
367-
385+
368386 getModulePath ( suite : TestSuite ) : Uri {
369387 return Uri . parse ( suite . modulePath || "" ) ;
370388 }
0 commit comments