forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartupTelemetry.unit.test.ts
More file actions
80 lines (70 loc) · 4.15 KB
/
startupTelemetry.unit.test.ts
File metadata and controls
80 lines (70 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { expect } from 'chai';
import * as TypeMoq from 'typemoq';
import { Uri, WorkspaceConfiguration } from 'vscode';
import { IWorkspaceService } from '../client/common/application/types';
import { DeprecatePythonPath } from '../client/common/experiments/groups';
import { IExperimentsManager, IInterpreterPathService } from '../client/common/types';
import { IServiceContainer } from '../client/ioc/types';
import { hasUserDefinedPythonPath } from '../client/startupTelemetry';
suite('Startup Telemetry - hasUserDefinedPythonPath()', async () => {
const resource = Uri.parse('a');
let serviceContainer: TypeMoq.IMock<IServiceContainer>;
let experimentsManager: TypeMoq.IMock<IExperimentsManager>;
let interpreterPathService: TypeMoq.IMock<IInterpreterPathService>;
let workspaceService: TypeMoq.IMock<IWorkspaceService>;
setup(() => {
serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>();
experimentsManager = TypeMoq.Mock.ofType<IExperimentsManager>();
interpreterPathService = TypeMoq.Mock.ofType<IInterpreterPathService>();
workspaceService = TypeMoq.Mock.ofType<IWorkspaceService>();
experimentsManager
.setup((e) => e.sendTelemetryIfInExperiment(DeprecatePythonPath.control))
.returns(() => undefined);
serviceContainer.setup((s) => s.get(IExperimentsManager)).returns(() => experimentsManager.object);
serviceContainer.setup((s) => s.get(IWorkspaceService)).returns(() => workspaceService.object);
serviceContainer.setup((s) => s.get(IInterpreterPathService)).returns(() => interpreterPathService.object);
});
function setupConfigProvider(): TypeMoq.IMock<WorkspaceConfiguration> {
const workspaceConfig = TypeMoq.Mock.ofType<WorkspaceConfiguration>();
workspaceService
.setup((w) => w.getConfiguration(TypeMoq.It.isValue('python'), TypeMoq.It.isValue(resource)))
.returns(() => workspaceConfig.object);
return workspaceConfig;
}
[undefined, 'python'].forEach((globalValue) => {
[undefined, 'python'].forEach((workspaceValue) => {
[undefined, 'python'].forEach((workspaceFolderValue) => {
test(`Return false if using settings equals {globalValue: ${globalValue}, workspaceValue: ${workspaceValue}, workspaceFolderValue: ${workspaceFolderValue}}`, () => {
experimentsManager
.setup((e) => e.inExperiment(DeprecatePythonPath.experiment))
.returns(() => false);
const workspaceConfig = setupConfigProvider();
workspaceConfig
.setup((w) => w.inspect('pythonPath'))
.returns(() => ({ globalValue, workspaceValue, workspaceFolderValue } as any));
const result = hasUserDefinedPythonPath(resource, serviceContainer.object);
expect(result).to.equal(false, 'Should be false');
});
});
});
});
test('Return true if using setting value equals something else', () => {
experimentsManager.setup((e) => e.inExperiment(DeprecatePythonPath.experiment)).returns(() => false);
const workspaceConfig = setupConfigProvider();
workspaceConfig.setup((w) => w.inspect('pythonPath')).returns(() => ({ globalValue: 'something else' } as any));
const result = hasUserDefinedPythonPath(resource, serviceContainer.object);
expect(result).to.equal(true, 'Should be true');
});
test('If in Deprecate PythonPath experiment, use the new API to inspect settings', () => {
experimentsManager.setup((e) => e.inExperiment(DeprecatePythonPath.experiment)).returns(() => true);
interpreterPathService
.setup((i) => i.inspect(resource))
.returns(() => ({}))
.verifiable(TypeMoq.Times.once());
hasUserDefinedPythonPath(resource, serviceContainer.object);
interpreterPathService.verifyAll();
});
});