forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.unit.test.ts
More file actions
70 lines (58 loc) · 3.72 KB
/
main.unit.test.ts
File metadata and controls
70 lines (58 loc) · 3.72 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import * as sinon from 'sinon';
import { anything, instance, mock, verify, when } from 'ts-mockito';
import { Disposable } from 'vscode';
import { CommandManager } from '../../client/common/application/commandManager';
import { ICommandManager } from '../../client/common/application/types';
import { AlwaysDisplayTestExplorerGroups } from '../../client/common/experimentGroups';
import { ExperimentsManager } from '../../client/common/experiments';
import { IDisposableRegistry, IExperimentsManager } from '../../client/common/types';
import { ServiceContainer } from '../../client/ioc/container';
import { IServiceContainer } from '../../client/ioc/types';
import { JediSymbolProvider } from '../../client/providers/symbolProvider';
import { UnitTestManagementService } from '../../client/testing/main';
suite('Unit Tests - ManagementService', () => {
suite('Experiments', () => {
let serviceContainer: IServiceContainer;
let sandbox: sinon.SinonSandbox;
let experiment: IExperimentsManager;
let commandManager: ICommandManager;
let testManagementService: UnitTestManagementService;
setup(() => {
serviceContainer = mock(ServiceContainer);
sandbox = sinon.createSandbox();
sandbox.stub(UnitTestManagementService.prototype, 'registerSymbolProvider');
sandbox.stub(UnitTestManagementService.prototype, 'registerCommands');
sandbox.stub(UnitTestManagementService.prototype, 'registerHandlers');
sandbox.stub(UnitTestManagementService.prototype, 'autoDiscoverTests').callsFake(() => Promise.resolve());
experiment = mock(ExperimentsManager);
commandManager = mock(CommandManager);
when(serviceContainer.get<Disposable[]>(IDisposableRegistry)).thenReturn([]);
when(serviceContainer.get<IExperimentsManager>(IExperimentsManager)).thenReturn(instance(experiment));
when(serviceContainer.get<ICommandManager>(ICommandManager)).thenReturn(instance(commandManager));
when(commandManager.executeCommand(anything(), anything(), anything())).thenResolve();
testManagementService = new UnitTestManagementService(instance(serviceContainer));
});
teardown(() => {
sandbox.restore();
});
test('Execute command if in experiment', async () => {
when(experiment.inExperiment(AlwaysDisplayTestExplorerGroups.experiment)).thenReturn(true);
await testManagementService.activate(instance(mock(JediSymbolProvider)));
verify(commandManager.executeCommand('setContext', 'testsDiscovered', true)).once();
verify(experiment.inExperiment(AlwaysDisplayTestExplorerGroups.experiment)).once();
verify(experiment.inExperiment(AlwaysDisplayTestExplorerGroups.control)).never();
verify(experiment.sendTelemetryIfInExperiment(anything())).never();
});
test('If not in experiment, check and send Telemetry for control group and do not execute command', async () => {
when(experiment.inExperiment(AlwaysDisplayTestExplorerGroups.experiment)).thenReturn(false);
await testManagementService.activate(instance(mock(JediSymbolProvider)));
verify(commandManager.executeCommand('setContext', 'testsDiscovered', anything())).never();
verify(experiment.inExperiment(AlwaysDisplayTestExplorerGroups.experiment)).once();
verify(experiment.inExperiment(AlwaysDisplayTestExplorerGroups.control)).never();
verify(experiment.sendTelemetryIfInExperiment(AlwaysDisplayTestExplorerGroups.control)).once();
});
});
});