@@ -9,12 +9,14 @@ import {
99 LogEvent ,
1010 LogLevel ,
1111 RuleDescription ,
12+ TelemetryEvent ,
1213 Violation ,
1314 Workspace
1415} from "@salesforce/code-analyzer-engine-api" ;
1516import path from "node:path" ;
1617import * as os from "node:os" ;
1718import process from "node:process" ;
19+ import { ESLint8EnginePlugin } from "@salesforce/code-analyzer-eslint8-engine" ;
1820
1921jest . setTimeout ( 30_000 ) ;
2022
@@ -46,6 +48,8 @@ describe('End to end test', () => {
4648 const defaultConfig : ConfigObject = await plugin . createEngineConfig ( availableEngineNames [ 0 ] , configValueExtractor ) ;
4749 const engine : Engine = await plugin . createEngine ( availableEngineNames [ 0 ] , defaultConfig ) ;
4850 const logEvents : LogEvent [ ] = [ ] ;
51+ const telemetryEvents : TelemetryEvent [ ] = [ ] ;
52+ engine . onEvent ( EventType . TelemetryEvent , ( e : TelemetryEvent ) => telemetryEvents . push ( e ) ) ;
4953 engine . onEvent ( EventType . LogEvent , ( e : LogEvent ) => logEvents . push ( e ) ) ;
5054 const workspace : Workspace = new Workspace ( 'id' , [ path . resolve ( '.' ) ] ) ;
5155 const ruleDescriptions : RuleDescription [ ] = await engine . describeRules ( { logFolder : os . tmpdir ( ) , workspace : workspace } ) ;
@@ -68,6 +72,8 @@ describe('End to end test', () => {
6872
6973 const warnLogs : LogEvent [ ] = logEvents . filter ( e => e . logLevel == LogLevel . Warn ) ;
7074 expect ( warnLogs ) . toHaveLength ( 0 ) ;
75+
76+ expect ( telemetryEvents ) . toHaveLength ( 0 ) ;
7177 } ) ;
7278
7379 it ( 'Test that we delegate to eslint v8 engine when user has specified legacy eslint config file' , async ( ) => {
@@ -80,7 +86,9 @@ describe('End to end test', () => {
8086 const defaultConfig : ConfigObject = await plugin . createEngineConfig ( 'eslint' , configValueExtractor ) ;
8187 const engine : Engine = await plugin . createEngine ( 'eslint' , defaultConfig ) ;
8288 const logEvents : LogEvent [ ] = [ ] ;
89+ const telemetryEvents : TelemetryEvent [ ] = [ ] ;
8390 engine . onEvent ( EventType . LogEvent , ( e : LogEvent ) => logEvents . push ( e ) ) ;
91+ engine . onEvent ( EventType . TelemetryEvent , ( e : TelemetryEvent ) => telemetryEvents . push ( e ) ) ;
8492 const workspace : Workspace = new Workspace ( 'id' , [ path . resolve ( '.' ) ] ) ;
8593 const ruleDescriptions : RuleDescription [ ] = await engine . describeRules ( { logFolder : os . tmpdir ( ) , workspace : workspace } ) ;
8694 const recommendedRuleNames : string [ ] = ruleDescriptions . filter ( rd => rd . tags . includes ( 'Recommended' ) ) . map ( rd => rd . name ) ;
@@ -104,5 +112,15 @@ describe('End to end test', () => {
104112 const warnLogs : LogEvent [ ] = logEvents . filter ( e => e . logLevel == LogLevel . Warn ) ;
105113 expect ( warnLogs ) . toHaveLength ( 1 ) ;
106114 expect ( warnLogs [ 0 ] . message ) . toContain ( 'Using ESLint v8 instead of ESLint v9' ) ;
115+
116+ expect ( telemetryEvents ) . toHaveLength ( 1 ) ;
117+ expect ( telemetryEvents [ 0 ] ) . toEqual ( {
118+ "type" : "TelemetryEvent" ,
119+ "eventName" : "eslintLegacyConfigDetected" ,
120+ "data" : {
121+ "eslint_engine_version" : await engine . getEngineVersion ( ) ,
122+ "eslint8_engine_version" : await ( await new ESLint8EnginePlugin ( ) . createEngine ( "eslint" , { } ) ) . getEngineVersion ( )
123+ }
124+ } ) ;
107125 } ) ;
108126} ) ;
0 commit comments