11import { QuickPickItem , window } from 'vscode' ;
22import * as vscode from 'vscode' ;
3- import { Tests , TestsToRun , TestFolder , TestFile , TestFunction , TestSuite , FlattenedTestFunction } from '../common/contracts' ;
3+ import { Tests , TestsToRun , TestFolder , TestFile , TestFunction , TestSuite , FlattenedTestFunction , TestStatus } from '../common/contracts' ;
44import { getDiscoveredTests } from '../common/testUtils' ;
55import * as constants from '../../common/constants' ;
66
@@ -9,12 +9,9 @@ export class TestDisplay {
99 }
1010 public displayTestUI ( ) {
1111 const tests = getDiscoveredTests ( ) ;
12- displayUI ( tests ) ;
12+ window . showQuickPick ( buildItems ( tests ) , { matchOnDescription : true , matchOnDetail : true } ) . then ( onItemSelected ) ;
1313 }
1414}
15- function displayUI ( tests ?: Tests ) {
16- window . showQuickPick ( buildItems ( tests ) , { matchOnDescription : true , matchOnDetail : true } ) . then ( onItemSelected ) ;
17- }
1815
1916enum Type {
2017 RunAll = 0 ,
@@ -26,31 +23,57 @@ enum Type {
2623 RunMethod = 6 ,
2724 ViewTestOutput = 7
2825}
26+ const statusIconMapping = new Map < TestStatus , string > ( ) ;
27+ statusIconMapping . set ( TestStatus . Pass , constants . Octicon_Test_Pass ) ;
28+ statusIconMapping . set ( TestStatus . Fail , constants . Octicon_Test_Fail ) ;
29+ statusIconMapping . set ( TestStatus . Error , constants . Octicon_Test_Error ) ;
30+ statusIconMapping . set ( TestStatus . Skipped , constants . Octicon_Test_Skip ) ;
31+
2932interface TestItem extends QuickPickItem {
3033 type : Type ;
3134 fn ?: FlattenedTestFunction ;
3235}
36+ function getSummary ( tests ?: Tests ) {
37+ if ( ! tests || ! tests . summary ) {
38+ return '' ;
39+ }
40+ const statusText = [ ] ;
41+ if ( tests . summary . passed > 0 ) {
42+ statusText . push ( `${ constants . Octicon_Test_Pass } ${ tests . summary . passed } ` ) ;
43+ }
44+ if ( tests . summary . failures > 0 ) {
45+ statusText . push ( `${ constants . Octicon_Test_Fail } ${ tests . summary . failures } ` ) ;
46+ }
47+ if ( tests . summary . errors > 0 ) {
48+ statusText . push ( `${ constants . Octicon_Test_Error } ${ tests . summary . errors } ` ) ;
49+ }
50+ if ( tests . summary . skipped > 0 ) {
51+ statusText . push ( `${ constants . Octicon_Test_Skip } ${ tests . summary . skipped } ` ) ;
52+ }
53+ return statusText . join ( ', ' ) . trim ( ) ;
54+ }
3355function buildItems ( tests ?: Tests ) : TestItem [ ] {
3456 const items : TestItem [ ] = [ ] ;
3557 items . push ( { description : '' , label : 'Run All Tests' , type : Type . RunAll } ) ;
3658 items . push ( { description : '' , label : 'Rediscover Tests' , type : Type . ReDiscover } ) ;
37- items . push ( { description : '' , label : 'View Test Output' , type : Type . ViewTestOutput } ) ;
59+ items . push ( { description : '' , label : 'View Test Output' , type : Type . ViewTestOutput , detail : getSummary ( tests ) } ) ;
3860
3961 if ( ! tests ) {
4062 return items ;
4163 }
4264
43- if ( tests . testFunctions . some ( fn => fn . testFunction . passed === false ) ) {
44- items . push ( { description : 'Run failed tests only ' , label : 'Run Failed Tests' , type : Type . RunFailed } ) ;
65+ if ( tests . summary . failures > 0 ) {
66+ items . push ( { description : '' , label : 'Run Failed Tests' , type : Type . RunFailed , detail : ` ${ constants . Octicon_Test_Fail } ${ tests . summary . failures } Failed` } ) ;
4567 }
4668
4769 let functionItems : TestItem [ ] = [ ] ;
4870 tests . testFunctions . forEach ( fn => {
4971 const classPrefix = fn . parentTestSuite ? fn . parentTestSuite . name + '.' : '' ;
72+ const icon = statusIconMapping . has ( fn . testFunction . status ) ? statusIconMapping . get ( fn . testFunction . status ) + ' ' : '' ;
5073 functionItems . push ( {
5174 description : '' ,
5275 detail : fn . parentTestFile . name ,
53- label : classPrefix + fn . testFunction . name ,
76+ label : icon + fn . testFunction . name ,
5477 type : Type . RunMethod ,
5578 fn : fn
5679 } ) ;
0 commit comments