diff --git a/lib/services/debug-service.ts b/lib/services/debug-service.ts index ab6e730835..2e488e32f5 100644 --- a/lib/services/debug-service.ts +++ b/lib/services/debug-service.ts @@ -31,7 +31,7 @@ export class DebugService extends EventEmitter implements IDebugService { await this.$analyticsService.trackEventActionInGoogleAnalytics({ action: TrackActionNames.Debug, device, - additionalData: this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform) && (!options || !options.chrome) ? DebugTools.Inspector : DebugTools.Chrome, + additionalData: this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform) && options && options.inspector ? DebugTools.Inspector : DebugTools.Chrome, projectDir: debugData.projectDir }); diff --git a/test/services/debug-service.ts b/test/services/debug-service.ts index 4c951fa587..8050cd0e55 100644 --- a/test/services/debug-service.ts +++ b/test/services/debug-service.ts @@ -4,7 +4,7 @@ import * as stubs from "../stubs"; import { assert } from "chai"; import { EventEmitter } from "events"; import * as constants from "../../lib/common/constants"; -import { CONNECTION_ERROR_EVENT_NAME, DebugCommandErrors } from "../../lib/constants"; +import { CONNECTION_ERROR_EVENT_NAME, DebugCommandErrors, TrackActionNames, DebugTools } from "../../lib/constants"; const fakeChromeDebugPort = 123; const fakeChromeDebugUrl = `fakeChromeDebugUrl?experiments=true&ws=localhost:${fakeChromeDebugPort}`; @@ -231,5 +231,53 @@ describe("debugService", () => { }); }); }); + + describe("tracks to google analytics", () => { + _.each([ + { + testName: "Inspector when --inspector is passed", + debugOptions: { inspector: true }, + additionalData: DebugTools.Inspector + }, + { + testName: "Chrome when no options are passed", + debugOptions: null, + additionalData: DebugTools.Chrome + }, + { + testName: "Chrome when --chrome is passed", + debugOptions: { chrome: true }, + additionalData: DebugTools.Chrome + }], testCase => { + + it(testCase.testName, async () => { + const testData = getDefaultTestData(); + testData.deviceInformation.deviceInfo.platform = "iOS"; + + const testInjector = getTestInjectorForTestConfiguration(testData); + const analyticsService = testInjector.resolve("analyticsService"); + let dataTrackedToGA: IEventActionData = null; + analyticsService.trackEventActionInGoogleAnalytics = async (data: IEventActionData): Promise => { + dataTrackedToGA = data; + }; + + const debugService = testInjector.resolve(DebugService); + const debugData = getDebugData(); + await debugService.debug(debugData, testCase.debugOptions); + const devicesService = testInjector.resolve("devicesService"); + const device = devicesService.getDeviceByIdentifier(testData.deviceInformation.deviceInfo.identifier); + + const expectedData = JSON.stringify({ + action: TrackActionNames.Debug, + device, + additionalData: testCase.additionalData, + projectDir: debugData.projectDir + }, null, 2); + + // Use JSON.stringify as the compared objects link to new instances of different classes. + assert.deepEqual(JSON.stringify(dataTrackedToGA, null, 2), expectedData); + }); + }); + }); }); });