From c2e79623a3a4539b2909c528396a56067ef0e62b Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Sun, 21 Nov 2021 15:10:07 -0800 Subject: [PATCH] start working --- .../terminal/browser/terminalActions.ts | 3 +- .../test/browser/terminalMultiroot.test.ts | 81 +++++++++++++++++++ .../areas/terminal/terminal-multiroot.test.ts | 31 +++++++ 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 src/vs/workbench/contrib/terminal/test/browser/terminalMultiroot.test.ts create mode 100644 test/smoke/src/areas/terminal/terminal-multiroot.test.ts diff --git a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts index 0ee189630af..115fe4e85a4 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts @@ -2181,7 +2181,7 @@ export function refreshTerminalActions(detectedProfiles: ITerminalProfile[]) { }, }); } - async run(accessor: ServicesAccessor, eventOrOptionsOrProfile: MouseEvent | ICreateTerminalOptions | ITerminalProfile | { profileName: string } | undefined, profile?: ITerminalProfile) { + async run(accessor: ServicesAccessor, eventOrOptionsOrProfile: MouseEvent | ICreateTerminalOptions | ITerminalProfile | { profileName: string } | undefined, profile?: ITerminalProfile): Promise { const terminalService = accessor.get(ITerminalService); const terminalProfileService = accessor.get(ITerminalProfileService); @@ -2246,6 +2246,7 @@ export function refreshTerminalActions(detectedProfiles: ITerminalProfile[]) { await terminalGroupService.showPanel(true); } } + return cwd; } }); } diff --git a/src/vs/workbench/contrib/terminal/test/browser/terminalMultiroot.test.ts b/src/vs/workbench/contrib/terminal/test/browser/terminalMultiroot.test.ts new file mode 100644 index 00000000000..c185ca472f5 --- /dev/null +++ b/src/vs/workbench/contrib/terminal/test/browser/terminalMultiroot.test.ts @@ -0,0 +1,81 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { deepStrictEqual } from 'assert'; +import { joinPath } from 'vs/base/common/resources'; +import { URI } from 'vs/base/common/uri'; +import { mock } from 'vs/base/test/common/mock'; +import { TestCommandService } from 'vs/editor/test/browser/editorTestServices'; +import { ICommandService } from 'vs/platform/commands/common/commands'; +import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; +import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock'; +import { IWorkspace, IWorkspaceContextService, toWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; +import { Workspace } from 'vs/platform/workspace/test/common/testWorkspace'; +import { PICK_WORKSPACE_FOLDER_COMMAND_ID } from 'vs/workbench/browser/actions/workspaceCommands'; +class TestWorkspaceContextService implements Partial { + private _folders: string[] = []; + getWorkspace(): IWorkspace { + return testWorkspace(this._folders); + } + setFolders(folders: string[]): void { + this._folders = folders; + } +} +class MockCommandService extends TestCommandService { + private _folderToChoose: string | undefined; + override async executeCommand(id: string, ...args: any[]): Promise { + if (id === PICK_WORKSPACE_FOLDER_COMMAND_ID) { + if (this._folderToChoose) { + const ROOT = URI.file('tests').with({ scheme: 'vscode-tests' }); + return toWorkspaceFolder(joinPath(ROOT, this._folderToChoose)) as any; + } else { + return undefined as any; + } + } else { + return super.executeCommand(id, args); + } + } + setPick(folder: string): void { + this._folderToChoose = folder; + } +} +export function testWorkspace(resources: string[]): Workspace { + const ROOT = URI.file('tests').with({ scheme: 'vscode-tests' }); + const folders = []; + for (const resource of resources) { + const folderDir = joinPath(ROOT, resource); + folders.push(toWorkspaceFolder(folderDir)); + } + return new Workspace('workspaceId', folders); +} + +suite('Workbench - Terminal - Multiroot', () => { + let commandService: MockCommandService; + let instantiationService: TestInstantiationService; + let workspaceContextService: TestWorkspaceContextService; + + setup(async function () { + instantiationService = new TestInstantiationService(); + new ServiceCollection( + [IWorkspaceContextService, new class extends mock() { }], + ); + commandService = instantiationService.createInstance(MockCommandService); + instantiationService.stub(ICommandService, commandService); + }); + + suite.only('multiroot', () => { + test('should not show prompt for single root', async () => { + workspaceContextService.setFolders(['folderA']); + const cwd = await commandService.executeCommand('workbench.action.terminal.new', undefined); + deepStrictEqual(cwd, undefined); + }); + test('should show prompt for multi root', async () => { + workspaceContextService.setFolders(['folderA', 'folderB']); + commandService.setPick('folderB'); + const cwd = await commandService.executeCommand('workbench.action.terminal.new', undefined); + deepStrictEqual(cwd, 'folderB'); + }); + }); +}); diff --git a/test/smoke/src/areas/terminal/terminal-multiroot.test.ts b/test/smoke/src/areas/terminal/terminal-multiroot.test.ts new file mode 100644 index 00000000000..bae3a409186 --- /dev/null +++ b/test/smoke/src/areas/terminal/terminal-multiroot.test.ts @@ -0,0 +1,31 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + + +import { ParsedArgs } from 'minimist'; +import { Terminal, TerminalCommandId } from '../../../../automation/out'; +import { afterSuite, beforeSuite, timeout } from '../../utils'; + +export function setup(opts: ParsedArgs) { + describe.only('Terminal Multiroot', () => { + let terminal: Terminal; + + beforeSuite(opts); + afterSuite(opts); + + before(function () { + terminal = this.app.workbench.terminal; + }); + + afterEach(async () => { + await terminal.runCommand(TerminalCommandId.KillAll); + }); + + it('should launch the default profile', async () => { + await terminal.runCommand(TerminalCommandId.Show); + await timeout(4000000); + }); + }); +}