@@ -9,20 +9,21 @@ import { expect, use } from 'chai';
99import * as chaiAsPromised from 'chai-as-promised' ;
1010import * as path from 'path' ;
1111import * as sinon from 'sinon' ;
12- import rewiremock from 'rewiremock' ;
12+ // import rewiremock from 'rewiremock';
1313import { SemVer } from 'semver' ;
1414import { instance , mock , when } from 'ts-mockito' ;
1515import { DebugAdapterExecutable , DebugAdapterServer , DebugConfiguration , DebugSession , WorkspaceFolder } from 'vscode' ;
1616import { IPersistentStateFactory } from '../../../extension/common/types' ;
1717import { DebugAdapterDescriptorFactory , debugStateKeys } from '../../../extension/debugger/adapter/factory' ;
1818import { IDebugAdapterDescriptorFactory } from '../../../extension/debugger/types' ;
19- import { clearTelemetryReporter } from '../../../extension/telemetry' ;
2019import { EventName } from '../../../extension/telemetry/constants' ;
2120import { PersistentState , PersistentStateFactory } from '../../../extension/common/persistentState' ;
22- import * as vscodeApi from '../../../extension/common/vscodeapi' ;
2321import { EXTENSION_ROOT_DIR } from '../../../extension/common/constants' ;
2422import { Architecture } from '../../../extension/common/platform' ;
2523import * as pythonApi from '../../../extension/common/python' ;
24+ import * as telemetry from '../../../extension/telemetry' ;
25+ import * as telemetryReporter from '../../../extension/telemetry/reporter' ;
26+ import * as vscodeApi from '../../../extension/common/vscodeapi' ;
2627import { DebugConfigStrings } from '../../../extension/common/utils/localize' ;
2728
2829use ( chaiAsPromised ) ;
@@ -36,6 +37,9 @@ suite('Debugging - Adapter Factory', () => {
3637 let getInterpretersStub : sinon . SinonStub ;
3738 let getInterpreterDetailsStub : sinon . SinonStub ;
3839 let hasInterpretersStub : sinon . SinonStub ;
40+ // let sendTelemetryEventStub: sinon.SinonStub;
41+ let getTelemetryReporterStub : sinon . SinonStub ;
42+ let reporter : any ;
3943
4044 const nodeExecutable = undefined ;
4145 const debugAdapterPath = path . join ( EXTENSION_ROOT_DIR , 'bundled' , 'libs' , 'debugpy' , 'adapter' ) ;
@@ -65,33 +69,35 @@ suite('Debugging - Adapter Factory', () => {
6569 setup ( ( ) => {
6670 process . env . VSC_PYTHON_UNIT_TEST = undefined ;
6771 process . env . VSC_PYTHON_CI_TEST = undefined ;
68- rewiremock . enable ( ) ;
69- rewiremock ( '@vscode/extension-telemetry' ) . with ( { default : Reporter } ) ;
72+ reporter = new Reporter ( ) ;
73+
7074 stateFactory = mock ( PersistentStateFactory ) ;
7175 state = mock ( PersistentState ) as PersistentState < boolean | undefined > ;
7276 showErrorMessageStub = sinon . stub ( vscodeApi , 'showErrorMessage' ) ;
7377 resolveEnvironmentStub = sinon . stub ( pythonApi , 'resolveEnvironment' ) ;
7478 getInterpretersStub = sinon . stub ( pythonApi , 'getInterpreters' ) ;
7579 getInterpreterDetailsStub = sinon . stub ( pythonApi , 'getInterpreterDetails' ) ;
7680 hasInterpretersStub = sinon . stub ( pythonApi , 'hasInterpreters' ) ;
81+ // sendTelemetryEventStub = sinon.stub(telemetry, 'sendTelemetryEvent');
82+ getTelemetryReporterStub = sinon . stub ( telemetryReporter , 'getTelemetryReporter' ) ;
7783
7884 when (
7985 stateFactory . createGlobalPersistentState < boolean | undefined > ( debugStateKeys . doNotShowAgain , false ) ,
8086 ) . thenReturn ( instance ( state ) ) ;
81-
8287 getInterpretersStub . returns ( [ interpreter ] ) ;
8388 hasInterpretersStub . returns ( true ) ;
89+ getTelemetryReporterStub . returns ( reporter ) ;
8490 factory = new DebugAdapterDescriptorFactory ( instance ( stateFactory ) ) ;
8591 } ) ;
8692
8793 teardown ( ( ) => {
8894 process . env . VSC_PYTHON_UNIT_TEST = oldValueOfVSC_PYTHON_UNIT_TEST ;
8995 process . env . VSC_PYTHON_CI_TEST = oldValueOfVSC_PYTHON_CI_TEST ;
90- Reporter . properties = [ ] ;
91- Reporter . eventNames = [ ] ;
92- Reporter . measures = [ ] ;
93- rewiremock . disable ( ) ;
94- clearTelemetryReporter ( ) ;
96+ reporter . properties = [ ] ;
97+ reporter . eventNames = [ ] ;
98+ reporter . measures = [ ] ;
99+ // rewiremock.disable();
100+ telemetry . clearTelemetryReporter ( ) ;
95101 sinon . restore ( ) ;
96102 } ) ;
97103
@@ -259,14 +265,14 @@ suite('Debugging - Adapter Factory', () => {
259265 assert . deepStrictEqual ( descriptor , debugExecutable ) ;
260266 } ) ;
261267
262- test ( 'Send attach to local process telemetry if attaching to a local process' , async ( ) => {
268+ test . only ( 'Send attach to local process telemetry if attaching to a local process' , async ( ) => {
263269 const session = createSession ( { request : 'attach' , processId : 1234 } ) ;
264270 getInterpreterDetailsStub . resolves ( { path : [ interpreter . path ] } ) ;
265271 resolveEnvironmentStub . withArgs ( interpreter . path ) . resolves ( interpreter ) ;
266272
267273 await factory . createDebugAdapterDescriptor ( session , nodeExecutable ) ;
268274
269- assert . ok ( Reporter . eventNames . includes ( EventName . DEBUGGER_ATTACH_TO_LOCAL_PROCESS ) ) ;
275+ assert . ok ( reporter . eventNames . includes ( EventName . DEBUGGER_ATTACH_TO_LOCAL_PROCESS ) ) ;
270276 } ) ;
271277
272278 test ( "Don't send any telemetry if not attaching to a local process" , async ( ) => {
0 commit comments