1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ 'use strict' ;
5
+
6
+ import { expect } from 'chai' ;
7
+ import * as sinon from 'sinon' ;
8
+ import * as windowApis from '../../../client/common/vscodeApis/windowApis' ;
9
+ import * as telemetryModule from '../../../client/telemetry' ;
10
+ import { EventName } from '../../../client/telemetry/constants' ;
11
+ import { registerTriggerForTerminalREPL } from '../../../client/terminals/codeExecution/terminalReplWatcher' ;
12
+
13
+ suite ( 'Terminal REPL Watcher' , ( ) => {
14
+ let windowApisStub : sinon . SinonStub ;
15
+ let telemetryStub : sinon . SinonStub ;
16
+
17
+ setup ( ( ) => {
18
+ windowApisStub = sinon . stub ( windowApis , 'onDidStartTerminalShellExecution' ) . returns ( {
19
+ dispose : ( ) => {
20
+ // Do nothing
21
+ }
22
+ } ) ;
23
+ telemetryStub = sinon . stub ( telemetryModule , 'sendTelemetryEvent' ) ;
24
+ } ) ;
25
+
26
+ teardown ( ( ) => {
27
+ sinon . restore ( ) ;
28
+ } ) ;
29
+
30
+ test ( 'Should send REPL telemetry when Python is invoked' , ( ) => {
31
+ windowApisStub . callsFake ( ( callback ) => {
32
+ callback ( {
33
+ execution : {
34
+ commandLine : {
35
+ value : 'python script.py' ,
36
+ isTrusted : true
37
+ }
38
+ }
39
+ } ) ;
40
+ return {
41
+ dispose : ( ) => {
42
+ // Do nothing
43
+ }
44
+ } ;
45
+ } ) ;
46
+
47
+ registerTriggerForTerminalREPL ( [ ] ) ;
48
+
49
+ expect ( telemetryStub . calledOnce ) . to . be . true ;
50
+ expect ( telemetryStub . args [ 0 ] [ 0 ] ) . to . equal ( EventName . REPL ) ;
51
+ expect ( telemetryStub . args [ 0 ] [ 2 ] ) . to . deep . equal ( { replType : 'runningScript' } ) ;
52
+ } ) ;
53
+
54
+ test ( 'Should send unittest CLI telemetry when pytest is invoked' , ( ) => {
55
+ windowApisStub . callsFake ( ( callback ) => {
56
+ callback ( {
57
+ execution : {
58
+ commandLine : {
59
+ value : 'python -m pytest' ,
60
+ isTrusted : true
61
+ }
62
+ }
63
+ } ) ;
64
+ return {
65
+ dispose : ( ) => {
66
+ // Do nothing
67
+ }
68
+ } ;
69
+ } ) ;
70
+
71
+ registerTriggerForTerminalREPL ( [ ] ) ;
72
+
73
+ expect ( telemetryStub . calledOnce ) . to . be . true ;
74
+ expect ( telemetryStub . args [ 0 ] [ 0 ] ) . to . equal ( EventName . UNITTEST_RUN_CLI ) ;
75
+ } ) ;
76
+
77
+ test ( 'Should send unittest CLI telemetry when unittest is invoked' , ( ) => {
78
+ windowApisStub . callsFake ( ( callback ) => {
79
+ callback ( {
80
+ execution : {
81
+ commandLine : {
82
+ value : 'python -m unittest discover' ,
83
+ isTrusted : true
84
+ }
85
+ }
86
+ } ) ;
87
+ return {
88
+ dispose : ( ) => {
89
+ // Do nothing
90
+ }
91
+ } ;
92
+ } ) ;
93
+
94
+ registerTriggerForTerminalREPL ( [ ] ) ;
95
+
96
+ expect ( telemetryStub . calledOnce ) . to . be . true ;
97
+ expect ( telemetryStub . args [ 0 ] [ 0 ] ) . to . equal ( EventName . UNITTEST_RUN_CLI ) ;
98
+ } ) ;
99
+
100
+ test ( 'Should send unittest CLI telemetry when nose is invoked' , ( ) => {
101
+ windowApisStub . callsFake ( ( callback ) => {
102
+ callback ( {
103
+ execution : {
104
+ commandLine : {
105
+ value : 'python -m nose' ,
106
+ isTrusted : true
107
+ }
108
+ }
109
+ } ) ;
110
+ return {
111
+ dispose : ( ) => {
112
+ // Do nothing
113
+ }
114
+ } ;
115
+ } ) ;
116
+
117
+ registerTriggerForTerminalREPL ( [ ] ) ;
118
+
119
+ expect ( telemetryStub . calledOnce ) . to . be . true ;
120
+ expect ( telemetryStub . args [ 0 ] [ 0 ] ) . to . equal ( EventName . UNITTEST_RUN_CLI ) ;
121
+ } ) ;
122
+
123
+ test ( 'Should send unittest CLI telemetry when py.test is invoked' , ( ) => {
124
+ windowApisStub . callsFake ( ( callback ) => {
125
+ callback ( {
126
+ execution : {
127
+ commandLine : {
128
+ value : 'py.test' ,
129
+ isTrusted : true
130
+ }
131
+ }
132
+ } ) ;
133
+ return {
134
+ dispose : ( ) => {
135
+ // Do nothing
136
+ }
137
+ } ;
138
+ } ) ;
139
+
140
+ registerTriggerForTerminalREPL ( [ ] ) ;
141
+
142
+ expect ( telemetryStub . calledOnce ) . to . be . true ;
143
+ expect ( telemetryStub . args [ 0 ] [ 0 ] ) . to . equal ( EventName . UNITTEST_RUN_CLI ) ;
144
+ } ) ;
145
+ } ) ;
0 commit comments