Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the isTelemetryEnabled provided by VSCode and fixing unit tests #472

Merged
merged 2 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const osName = require('os-name');

export const areAllTelemetryConfigsEnabled = () => {
// respect both the overall and Stripe-specific telemetry configs
const enableTelemetry = vscode.workspace
.getConfiguration('telemetry')
.get('enableTelemetry', false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also remove this from package.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't exist in our package.json because it's the VSCode-wide telemetry setting. We will still reference stripe.telemetry.enabled which allows users to configure Stripe telemetry separately.

const enableTelemetry = vscode.env.isTelemetryEnabled;

const stripeEnableTelemetry = vscode.workspace
.getConfiguration('stripe.telemetry')
Expand Down
44 changes: 25 additions & 19 deletions test/suite/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {mocks} from '../mocks/vscode';
import sinon from 'ts-sinon';

const https = require('https');
const proxyquire = require('proxyquire');
const modulePath = '../../src/telemetry';

const setupProxies = (proxies: any) => proxyquire(modulePath, proxies);

suite('Telemetry', function () {
this.timeout(20000);
Expand All @@ -22,28 +26,30 @@ suite('Telemetry', function () {
suite('StripeAnalyticsServiceTelemetry', () => {
const extensionContext = {...mocks.extensionContextMock};

test('Respects overall and Stripe-specific telemetry configs', () => {
test('Respects overall and Stripe-specific telemetry configs', async () => {
const getConfigurationStub = sandbox.stub(vscode.workspace, 'getConfiguration');
await Promise.all(
[
[false, false, false],
[false, true, false],
[true, false, false],
[true, true, true],
].map(([telemetryEnabled, stripeTelemetryEnabled, expected]) => {
const vscodeStub = {
env: <any>{
isTelemetryEnabled: telemetryEnabled,
},
};
const module = setupProxies({vscode: vscodeStub});
getConfigurationStub.withArgs('stripe.telemetry').returns(<any>{
get: sandbox.stub().withArgs('enabled').returns(stripeTelemetryEnabled),
});

[
[false, false, false],
[false, true, false],
[true, false, false],
[true, true, true],
].forEach(async ([telemetryEnabled, stripeTelemetryEnabled, expected]) => {
getConfigurationStub.withArgs('telemetry').returns(<any>{
get: sandbox.stub().withArgs('telemetryEnabled').returns(telemetryEnabled),
});
getConfigurationStub
.withArgs('stripe.telemetry')
.returns(<any>{get: sandbox.stub().withArgs('enabled').returns(stripeTelemetryEnabled)});

// Simulate a config change
await vscode.workspace.getConfiguration('telemetry').update('stripe', undefined);
const telemetry = new StripeAnalyticsServiceTelemetry(extensionContext);
const telemetry = new module.StripeAnalyticsServiceTelemetry(extensionContext);

assert.strictEqual(telemetry.isTelemetryEnabled(), expected);
});
assert.strictEqual(telemetry.isTelemetryEnabled(), expected);
}),
);
});

test('sendEvent respects user telemetry settings', () => {
Expand Down