22
33import * as vscode from 'vscode' ;
44import { CodeLensProvider , TextDocument , CancellationToken , CodeLens , SymbolInformation } from 'vscode' ;
5- import { TestFile , TestsToRun , TestSuite , TestFunction } from '../common/contracts' ;
5+ import { TestFile , TestsToRun , TestSuite , TestFunction , TestStatus } from '../common/contracts' ;
66import * as constants from '../../common/constants' ;
77import { getDiscoveredTests } from '../common/testUtils' ;
88
@@ -17,6 +17,13 @@ interface FunctionsAndSuites {
1717}
1818
1919export class TestFileCodeLensProvider implements CodeLensProvider {
20+ constructor ( private _onDidChange : vscode . EventEmitter < void > ) {
21+ }
22+
23+ get onDidChangeCodeLenses ( ) : vscode . Event < void > {
24+ return this . _onDidChange . event ;
25+ }
26+
2027 public provideCodeLenses ( document : TextDocument , token : CancellationToken ) : Thenable < CodeLens [ ] > {
2128 let testItems = getDiscoveredTests ( ) ;
2229 if ( ! testItems || testItems . testFiles . length === 0 || testItems . testFunctions . length === 0 ) {
@@ -96,12 +103,12 @@ function getCodeLens(fileName: string, allFuncsAndSuites: FunctionsAndSuites,
96103 }
97104 return [
98105 new CodeLens ( range , {
99- title : constants . Text . CodeLensRunUnitTest ,
106+ title : getTestStatusIcon ( cls . status ) + constants . Text . CodeLensRunUnitTest ,
100107 command : constants . Commands . Tests_Run ,
101108 arguments : [ < TestsToRun > { testSuite : [ cls ] } ]
102109 } ) ,
103110 new CodeLens ( range , {
104- title : constants . Text . CodeLensDebugUnitTest ,
111+ title : getTestStatusIcon ( cls . status ) + constants . Text . CodeLensDebugUnitTest ,
105112 command : constants . Commands . Tests_Debug ,
106113 arguments : [ < TestsToRun > { testSuite : [ cls ] } ]
107114 } )
@@ -112,19 +119,54 @@ function getCodeLens(fileName: string, allFuncsAndSuites: FunctionsAndSuites,
112119 return null ;
113120}
114121
122+ function getTestStatusIcon ( status : TestStatus ) : string {
123+ switch ( status ) {
124+ case TestStatus . Pass : {
125+ return '✔ ' ;
126+ }
127+ case TestStatus . Error :
128+ case TestStatus . Fail : {
129+ return '✘ ' ;
130+ }
131+ case TestStatus . Skipped : {
132+ return '⃠ ' ;
133+ }
134+ default : {
135+ return '' ;
136+ }
137+ }
138+ }
139+
140+ function getTestStatusIcons ( fns : TestFunction [ ] ) : string {
141+ let statuses : string [ ] = [ ] ;
142+ let count = fns . filter ( fn => fn . status === TestStatus . Pass ) . length ;
143+ if ( count > 0 ) {
144+ statuses . push ( `✔ ${ count } ` ) ;
145+ }
146+ count = fns . filter ( fn => fn . status === TestStatus . Error || fn . status === TestStatus . Fail ) . length ;
147+ if ( count > 0 ) {
148+ statuses . push ( `✘ ${ count } ` ) ;
149+ }
150+ count = fns . filter ( fn => fn . status === TestStatus . Skipped ) . length ;
151+ if ( count > 0 ) {
152+ statuses . push ( `⃠ ${ count } ` ) ;
153+ }
154+
155+ return statuses . join ( ' ' ) ;
156+ }
115157function getFunctionCodeLens ( filePath : string , functionsAndSuites : FunctionsAndSuites ,
116158 symbolName : string , range : vscode . Range ) : vscode . CodeLens [ ] {
117159
118160 const fn = functionsAndSuites . functions . find ( fn => fn . name === symbolName ) ;
119161 if ( fn ) {
120162 return [
121163 new CodeLens ( range , {
122- title : constants . Text . CodeLensRunUnitTest ,
164+ title : getTestStatusIcon ( fn . status ) + constants . Text . CodeLensRunUnitTest ,
123165 command : constants . Commands . Tests_Run ,
124166 arguments : [ < TestsToRun > { testFunction : [ fn ] } ]
125167 } ) ,
126168 new CodeLens ( range , {
127- title : constants . Text . CodeLensDebugUnitTest ,
169+ title : getTestStatusIcon ( fn . status ) + constants . Text . CodeLensDebugUnitTest ,
128170 command : constants . Commands . Tests_Debug ,
129171 arguments : [ < TestsToRun > { testFunction : [ fn ] } ]
130172 } )
@@ -155,12 +197,12 @@ function getFunctionCodeLens(filePath: string, functionsAndSuites: FunctionsAndS
155197 // Find all flattened functions
156198 return [
157199 new CodeLens ( range , {
158- title : constants . Text . CodeLensRunUnitTest + ' (Multiple)' ,
200+ title : getTestStatusIcons ( functions ) + constants . Text . CodeLensRunUnitTest + ' (Multiple)' ,
159201 command : constants . Commands . Tests_Picker_UI ,
160202 arguments : [ filePath , functions ]
161203 } ) ,
162204 new CodeLens ( range , {
163- title : constants . Text . CodeLensDebugUnitTest + ' (Multiple)' ,
205+ title : getTestStatusIcons ( functions ) + constants . Text . CodeLensDebugUnitTest + ' (Multiple)' ,
164206 command : constants . Commands . Tests_Picker_UI_Debug ,
165207 arguments : [ filePath , functions ]
166208 } )
0 commit comments