import * as chai from 'chai' ; import * as sinon from 'sinon' ; import * as sinonChai from 'sinon-chai' ; import { ExtensionUtil } from '../../extension/util/ExtensionUtil' ; import { Reporter } from '../../extension/util/Reporter' ; chai . should ( ) ; chai . use ( sinonChai ) ; describe ( 'Reporter Tests' , ( ) => { let mySandBox ; beforeEach ( ( ) => { mySandBox = sinon . createSandbox ( ) ; } ) ; afterEach ( ( ) => { mySandBox . restore ( ) ; } ) ; it ( 'should send telemetry event if production release' , async ( ) => { const reporter = Reporter . instance ( ) ; const sendSpy = mySandBox . stub ( reporter [ 'telemetryReporter' ] , 'sendTelemetryEvent' ) ; mySandBox . stub ( ExtensionUtil , 'getPackageJSON' ) . returns ( { production : true } ) ; reporter . sendTelemetryEvent ( 'testEvent' , { test : 'testdata' } ) ; sendSpy . should . have . been . calledWith ( 'testEvent' , { test : 'testdata' } ) ; } ) ; it ( 'shouldnt send telemetry event if not a production release' , async ( ) => { const reporter = Reporter . instance ( ) ; const sendSpy = mySandBox . stub ( reporter [ 'telemetryReporter' ] , 'sendTelemetryEvent' ) ; mySandBox . stub ( ExtensionUtil , 'getPackageJSON' ) . returns ( { production : false } ) ; reporter . sendTelemetryEvent ( 'testEvent' , { test : 'testdata' } ) ; sendSpy . should . not . have . been . called ; } ) ; it ( 'should dispose the reporter' , async ( ) => { const reporter = Reporter . instance ( ) ; const disposeSpy = mySandBox . stub ( reporter [ 'telemetryReporter' ] , 'dispose' ) ; await reporter . dispose ( ) ; disposeSpy . should . have . been . called ; } ) ; } ) ;