Skip to content

Commit

Permalink
Reenable Telemetry tests and fix issue with the suite not running (#1980
Browse files Browse the repository at this point in the history
)

* Removing circular reference for TelemetryService

* Bring back commented out telemetry tests.
  • Loading branch information
KrisGraySFDC authored Feb 14, 2020
1 parent 93da562 commit 52db52e
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import * as util from 'util';
import * as vscode from 'vscode';
import TelemetryReporter from 'vscode-extension-telemetry';
import { telemetryService } from '.';
// import { telemetryService } from '.';
import { waitForDX } from '../dxsupport/waitForDX';

const EXTENSION_NAME = 'salesforcedx-vscode-lightning';
Expand All @@ -31,6 +31,7 @@ export class TelemetryService {
}

public async setupVSCodeTelemetry() {
const telemetryService = TelemetryService.getInstance();
// if its already set up
if (this.reporter) {
return Promise.resolve(telemetryService);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,126 +1,126 @@
// /*
// * Copyright (c) 2019, salesforce.com, inc.
// * All rights reserved.
// * Licensed under the BSD 3-Clause license.
// * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
// */
// import { assert, match, SinonStub, stub } from 'sinon';
// import TelemetryReporter from 'vscode-extension-telemetry';
// import { TelemetryService } from '../../../src/telemetry/telemetry';

// describe('Telemetry', () => {
// let reporter: TelemetryReporter;
// let sendEvent: SinonStub;
// let sendExceptionEvent: SinonStub;
// let processHrtimeStub: SinonStub;
// const mockDuration = [100, 100];

// beforeEach(() => {
// reporter = new TelemetryReporter(
// 'salesforcedx-vscode-lightning',
// 'v1',
// 'test87349-0'
// );
// sendEvent = stub(reporter, 'sendTelemetryEvent');
// // @ts-ignore
// reporter.sendExceptionEvent = () => {};
// // @ts-ignore
// sendExceptionEvent = stub(reporter, 'sendExceptionEvent');
// processHrtimeStub = stub(process, 'hrtime');
// processHrtimeStub.returns(mockDuration);
// });

// afterEach(async () => {
// sendEvent.restore();
// sendExceptionEvent.restore();
// processHrtimeStub.restore();
// await reporter.dispose();
// });

// it('Should send telemetry data', async () => {
// const telemetryService = TelemetryService.getInstance();
// telemetryService.initializeService(reporter, true);

// await telemetryService.sendExtensionActivationEvent([0, 600]);
// assert.calledOnce(sendEvent);
// });

// it('Should not send telemetry data', async () => {
// const telemetryService = TelemetryService.getInstance();
// telemetryService.initializeService(reporter, false);

// await telemetryService.sendExtensionActivationEvent([0, 700]);
// assert.notCalled(sendEvent);
// });

// it('Should send correct data format on sendExtensionActivationEvent', async () => {
// const telemetryService = TelemetryService.getInstance();
// telemetryService.initializeService(reporter, true);

// await telemetryService.sendExtensionActivationEvent([0, 800]);
// assert.calledOnce(sendEvent);

// const expectedData = {
// extensionName: 'salesforcedx-vscode-lightning',
// startupTime: match.string
// };
// assert.calledWith(sendEvent, 'activationEvent', match(expectedData));
// });

// it('Should send correct data format on sendExtensionDeactivationEvent', async () => {
// const telemetryService = TelemetryService.getInstance();
// telemetryService.initializeService(reporter, true);

// await telemetryService.sendExtensionDeactivationEvent();
// assert.calledOnce(sendEvent);

// const expectedData = {
// extensionName: 'salesforcedx-vscode-lightning'
// };
// assert.calledWith(sendEvent, 'deactivationEvent', expectedData);
// });

// it('Should send correct data format on sendCommandEvent', async () => {
// const telemetryService = TelemetryService.getInstance();
// telemetryService.initializeService(reporter, true);

// const mockCommandLogName = 'force_lightning_mock_command';
// const mockCommandHrstart: [number, number] = [100, 200];
// const mockAdditionalData = { mockKey: 'mockValue' };
// const mockCommandDuration = [300, 400];
// processHrtimeStub.returns(mockCommandDuration);
// await telemetryService.sendCommandEvent(
// mockCommandLogName,
// mockCommandHrstart,
// mockAdditionalData
// );
// assert.calledOnce(sendEvent);

// const expectedExecutionTime = '3000.0004';
// const expectedData = {
// extensionName: 'salesforcedx-vscode-lightning',
// commandName: mockCommandLogName,
// executionTime: expectedExecutionTime,
// mockKey: 'mockValue'
// };
// assert.calledWith(sendEvent, 'commandExecution', match(expectedData));
// });

// it('Should send correct data format on sendException', async () => {
// const telemetryService = TelemetryService.getInstance();
// telemetryService.initializeService(reporter, true);

// const mockExceptionLogName = 'force_lightning_mock_exception';
// const mockErrorMessage = 'mockError';
// await telemetryService.sendException(
// mockExceptionLogName,
// mockErrorMessage
// );
// assert.calledOnce(sendExceptionEvent);
// assert.calledWith(
// sendExceptionEvent,
// mockExceptionLogName,
// mockErrorMessage
// );
// });
// });
/*
* Copyright (c) 2019, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { assert, match, SinonStub, stub } from 'sinon';
import TelemetryReporter from 'vscode-extension-telemetry';
import { TelemetryService } from '../../../src/telemetry/telemetry';

describe('Telemetry', () => {
let reporter: TelemetryReporter;
let sendEvent: SinonStub;
let sendExceptionEvent: SinonStub;
let processHrtimeStub: SinonStub;
const mockDuration = [100, 100];

beforeEach(() => {
reporter = new TelemetryReporter(
'salesforcedx-vscode-lightning',
'v1',
'test87349-0'
);
sendEvent = stub(reporter, 'sendTelemetryEvent');
// @ts-ignore
reporter.sendExceptionEvent = () => {};
// @ts-ignore
sendExceptionEvent = stub(reporter, 'sendExceptionEvent');
processHrtimeStub = stub(process, 'hrtime');
processHrtimeStub.returns(mockDuration);
});

afterEach(async () => {
sendEvent.restore();
sendExceptionEvent.restore();
processHrtimeStub.restore();
await reporter.dispose();
});

it('Should send telemetry data', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, true);

await telemetryService.sendExtensionActivationEvent([0, 600]);
assert.calledOnce(sendEvent);
});

it('Should not send telemetry data', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, false);

await telemetryService.sendExtensionActivationEvent([0, 700]);
assert.notCalled(sendEvent);
});

it('Should send correct data format on sendExtensionActivationEvent', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, true);

await telemetryService.sendExtensionActivationEvent([0, 800]);
assert.calledOnce(sendEvent);

const expectedData = {
extensionName: 'salesforcedx-vscode-lightning',
startupTime: match.string
};
assert.calledWith(sendEvent, 'activationEvent', match(expectedData));
});

it('Should send correct data format on sendExtensionDeactivationEvent', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, true);

await telemetryService.sendExtensionDeactivationEvent();
assert.calledOnce(sendEvent);

const expectedData = {
extensionName: 'salesforcedx-vscode-lightning'
};
assert.calledWith(sendEvent, 'deactivationEvent', expectedData);
});

it('Should send correct data format on sendCommandEvent', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, true);

const mockCommandLogName = 'force_lightning_mock_command';
const mockCommandHrstart: [number, number] = [100, 200];
const mockAdditionalData = { mockKey: 'mockValue' };
const mockCommandDuration = [300, 400];
processHrtimeStub.returns(mockCommandDuration);
await telemetryService.sendCommandEvent(
mockCommandLogName,
mockCommandHrstart,
mockAdditionalData
);
assert.calledOnce(sendEvent);

const expectedExecutionTime = '3000.0004';
const expectedData = {
extensionName: 'salesforcedx-vscode-lightning',
commandName: mockCommandLogName,
executionTime: expectedExecutionTime,
mockKey: 'mockValue'
};
assert.calledWith(sendEvent, 'commandExecution', match(expectedData));
});

it('Should send correct data format on sendException', async () => {
const telemetryService = TelemetryService.getInstance();
telemetryService.initializeService(reporter, true);

const mockExceptionLogName = 'force_lightning_mock_exception';
const mockErrorMessage = 'mockError';
await telemetryService.sendException(
mockExceptionLogName,
mockErrorMessage
);
assert.calledOnce(sendExceptionEvent);
assert.calledWith(
sendExceptionEvent,
mockExceptionLogName,
mockErrorMessage
);
});
});

0 comments on commit 52db52e

Please sign in to comment.