22// Licensed under the MIT license.
33
44import * as _ from 'lodash' ;
5+ import * as path from 'path' ;
56import { CancellationToken , DebugConfiguration , Disposable , FileSystemWatcher , RelativePattern , TestController , TestItem , TestRun , TestRunProfileKind , TestRunRequest , tests , TestTag , Uri , window , workspace , WorkspaceFolder } from 'vscode' ;
67import { instrumentOperation , sendError , sendInfo } from 'vscode-extension-telemetry-wrapper' ;
78import { refreshExplorer } from '../commands/testExplorerCommands' ;
@@ -215,9 +216,6 @@ export const runTests: (request: TestRunRequest, option: IRunOption) => any = in
215216 testRun : run ,
216217 workspaceFolder,
217218 } ;
218- sendInfo ( operationId , {
219- testFramework : TestKind [ testContext . kind ] ,
220- } ) ;
221219 const runner : BaseRunner | undefined = getRunnerByContext ( testContext ) ;
222220 if ( ! runner ) {
223221 window . showErrorMessage ( `Failed to get suitable runner for the test kind: ${ testContext . kind } .` ) ;
@@ -228,6 +226,7 @@ export const runTests: (request: TestRunRequest, option: IRunOption) => any = in
228226 const resolvedConfiguration : DebugConfiguration = mergeConfigurations ( option . launchConfiguration , config ) ?? await resolveLaunchConfigurationForRunner ( runner , testContext , config ) ;
229227 resolvedConfiguration . __progressId = option . progressReporter ?. getId ( ) ;
230228 delegatedToDebugger = true ;
229+ trackTestFrameworkVersion ( testContext . kind , resolvedConfiguration . classPaths , resolvedConfiguration . modulePaths ) ;
231230 await runner . run ( resolvedConfiguration , token , option . progressReporter ) ;
232231 } catch ( error ) {
233232 window . showErrorMessage ( error . message || 'Failed to run tests.' ) ;
@@ -543,6 +542,36 @@ function getRunnerByContext(testContext: IRunTestContext): BaseRunner | undefine
543542 }
544543}
545544
545+ function trackTestFrameworkVersion ( testKind : TestKind , classpaths : string [ ] , modulepaths : string [ ] ) {
546+ let artifactPattern : RegExp ;
547+ switch ( testKind ) {
548+ case TestKind . JUnit :
549+ artifactPattern = / j u n i t - ( \d + \. \d + \. \d + ( - [ a - z A - Z \d ] + ) ? ) .j a r / ;
550+ break ;
551+ case TestKind . JUnit5 :
552+ artifactPattern = / j u n i t - j u p i t e r - a p i - ( \d + \. \d + \. \d + ( - [ a - z A - Z \d ] + ) ? ) .j a r / ;
553+ break ;
554+ case TestKind . TestNG :
555+ artifactPattern = / t e s t n g - ( \d + \. \d + \. \d + ( - [ a - z A - Z \d ] + ) ? ) .j a r / ;
556+ break ;
557+ default :
558+ return ;
559+ }
560+ let version : string = 'unknown' ;
561+ for ( const entry of [ ...classpaths , ...modulepaths ] ) {
562+ const fileName : string = path . basename ( entry ) ;
563+ const match : RegExpMatchArray | null = artifactPattern . exec ( fileName ) ;
564+ if ( match ) {
565+ version = match [ 1 ] ;
566+ break ;
567+ }
568+ }
569+ sendInfo ( '' , {
570+ testFramework : testKind ,
571+ version,
572+ } ) ;
573+ }
574+
546575interface IRunOption {
547576 isDebug : boolean ;
548577 progressReporter ?: IProgressReporter ;
0 commit comments