Skip to content

Commit 04ef22f

Browse files
Merge pull request #3589 from NativeScript/vladimirov/fix-inspector-tracking
fix: Tracking for used Debug tool is incorrect
2 parents 932fd75 + 001aa7e commit 04ef22f

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

lib/services/debug-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class DebugService extends EventEmitter implements IDebugService {
3131
await this.$analyticsService.trackEventActionInGoogleAnalytics({
3232
action: TrackActionNames.Debug,
3333
device,
34-
additionalData: this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform) && (!options || !options.chrome) ? DebugTools.Inspector : DebugTools.Chrome,
34+
additionalData: this.$mobileHelper.isiOSPlatform(device.deviceInfo.platform) && options && options.inspector ? DebugTools.Inspector : DebugTools.Chrome,
3535
projectDir: debugData.projectDir
3636
});
3737

test/services/debug-service.ts

+49-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as stubs from "../stubs";
44
import { assert } from "chai";
55
import { EventEmitter } from "events";
66
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";
88

99
const fakeChromeDebugPort = 123;
1010
const fakeChromeDebugUrl = `fakeChromeDebugUrl?experiments=true&ws=localhost:${fakeChromeDebugPort}`;
@@ -231,5 +231,53 @@ describe("debugService", () => {
231231
});
232232
});
233233
});
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+
});
234282
});
235283
});

0 commit comments

Comments
 (0)