|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +'use strict'; |
| 5 | + |
| 6 | +import { expect } from 'chai'; |
| 7 | +import { anything, reset, verify, when } from 'ts-mockito'; |
| 8 | +import { Disposable, Uri } from 'vscode'; |
| 9 | +import { mockedVSCodeNamespaces } from '../vscode-mock'; |
| 10 | +import { RecommendedEnvironmentService } from '../../client/interpreter/configuration/recommededEnvironmentService'; |
| 11 | + |
| 12 | +suite('RecommendedEnvironmentService - activate', () => { |
| 13 | + let service: RecommendedEnvironmentService; |
| 14 | + let subscriptions: Disposable[]; |
| 15 | + |
| 16 | + setup(() => { |
| 17 | + subscriptions = []; |
| 18 | + const extensionContext = { |
| 19 | + subscriptions, |
| 20 | + globalState: { |
| 21 | + get: () => undefined, |
| 22 | + update: () => Promise.resolve(), |
| 23 | + }, |
| 24 | + } as any; |
| 25 | + |
| 26 | + when(mockedVSCodeNamespaces.commands!.registerCommand(anything(), anything())).thenReturn({ |
| 27 | + dispose: () => {}, |
| 28 | + } as Disposable); |
| 29 | + |
| 30 | + service = new RecommendedEnvironmentService(extensionContext); |
| 31 | + }); |
| 32 | + |
| 33 | + teardown(() => { |
| 34 | + reset(mockedVSCodeNamespaces.commands!); |
| 35 | + }); |
| 36 | + |
| 37 | + test('Multiroot workspace: command is registered only once across multiple activate calls', async () => { |
| 38 | + // Simulate multiroot workspace where activate is called once per workspace root |
| 39 | + const workspaceRoot1 = Uri.file('/workspace/root1'); |
| 40 | + const workspaceRoot2 = Uri.file('/workspace/root2'); |
| 41 | + const workspaceRoot3 = Uri.file('/workspace/root3'); |
| 42 | + |
| 43 | + await service.activate(workspaceRoot1); |
| 44 | + await service.activate(workspaceRoot2); |
| 45 | + await service.activate(workspaceRoot3); |
| 46 | + |
| 47 | + verify(mockedVSCodeNamespaces.commands!.registerCommand('python.getRecommendedEnvironment', anything())).once(); |
| 48 | + expect(subscriptions).to.have.lengthOf(1); |
| 49 | + }); |
| 50 | +}); |
0 commit comments