@@ -4,7 +4,7 @@ import * as stubs from "../stubs";
4
4
import { assert } from "chai" ;
5
5
import { EventEmitter } from "events" ;
6
6
import * as constants from "../../lib/common/constants" ;
7
- import { CONNECTION_ERROR_EVENT_NAME , DebugCommandErrors } from "../../lib/constants" ;
7
+ import { CONNECTION_ERROR_EVENT_NAME , DebugCommandErrors , TrackActionNames , DebugTools } from "../../lib/constants" ;
8
8
9
9
const fakeChromeDebugPort = 123 ;
10
10
const fakeChromeDebugUrl = `fakeChromeDebugUrl?experiments=true&ws=localhost:${ fakeChromeDebugPort } ` ;
@@ -231,5 +231,53 @@ describe("debugService", () => {
231
231
} ) ;
232
232
} ) ;
233
233
} ) ;
234
+
235
+ describe ( "tracks to google analytics" , ( ) => {
236
+ _ . each ( [
237
+ {
238
+ testName : "Inspector when --inspector is passed" ,
239
+ debugOptions : { inspector : true } ,
240
+ additionalData : DebugTools . Inspector
241
+ } ,
242
+ {
243
+ testName : "Chrome when no options are passed" ,
244
+ debugOptions : null ,
245
+ additionalData : DebugTools . Chrome
246
+ } ,
247
+ {
248
+ testName : "Chrome when --chrome is passed" ,
249
+ debugOptions : { chrome : true } ,
250
+ additionalData : DebugTools . Chrome
251
+ } ] , testCase => {
252
+
253
+ it ( testCase . testName , async ( ) => {
254
+ const testData = getDefaultTestData ( ) ;
255
+ testData . deviceInformation . deviceInfo . platform = "iOS" ;
256
+
257
+ const testInjector = getTestInjectorForTestConfiguration ( testData ) ;
258
+ const analyticsService = testInjector . resolve < IAnalyticsService > ( "analyticsService" ) ;
259
+ let dataTrackedToGA : IEventActionData = null ;
260
+ analyticsService . trackEventActionInGoogleAnalytics = async ( data : IEventActionData ) : Promise < void > => {
261
+ dataTrackedToGA = data ;
262
+ } ;
263
+
264
+ const debugService = testInjector . resolve < IDebugServiceBase > ( DebugService ) ;
265
+ const debugData = getDebugData ( ) ;
266
+ await debugService . debug ( debugData , testCase . debugOptions ) ;
267
+ const devicesService = testInjector . resolve < Mobile . IDevicesService > ( "devicesService" ) ;
268
+ const device = devicesService . getDeviceByIdentifier ( testData . deviceInformation . deviceInfo . identifier ) ;
269
+
270
+ const expectedData = JSON . stringify ( {
271
+ action : TrackActionNames . Debug ,
272
+ device,
273
+ additionalData : testCase . additionalData ,
274
+ projectDir : debugData . projectDir
275
+ } , null , 2 ) ;
276
+
277
+ // Use JSON.stringify as the compared objects link to new instances of different classes.
278
+ assert . deepEqual ( JSON . stringify ( dataTrackedToGA , null , 2 ) , expectedData ) ;
279
+ } ) ;
280
+ } ) ;
281
+ } ) ;
234
282
} ) ;
235
283
} ) ;
0 commit comments