Clean up terminal creation in smoke tests

This commit is contained in:
Daniel Imms 2021-12-13 16:54:42 -08:00
parent 73a19337ac
commit 50f96a3c6b
6 changed files with 26 additions and 18 deletions

View file

@ -21,16 +21,21 @@ export enum Selector {
SplitButton = '.editor .codicon-split-horizontal'
}
/**
* Terminal commands that accept a value in a quick input.
*/
export enum TerminalCommandIdWithValue {
Rename = 'workbench.action.terminal.rename',
ChangeColor = 'workbench.action.terminal.changeColor',
ChangeIcon = 'workbench.action.terminal.changeIcon',
NewWithProfile = 'workbench.action.terminal.newWithProfile',
SelectDefaultProfile = 'workbench.action.terminal.selectDefaultShell',
AttachToSession = 'workbench.action.terminal.attachToSession',
CreateNew = 'workbench.action.terminal.new'
AttachToSession = 'workbench.action.terminal.attachToSession'
}
/**
* Terminal commands that do not present a quick input.
*/
export enum TerminalCommandId {
Split = 'workbench.action.terminal.split',
KillAll = 'workbench.action.terminal.killAll',
@ -44,6 +49,7 @@ export enum TerminalCommandId {
NewWithProfile = 'workbench.action.terminal.newWithProfile',
SelectDefaultProfile = 'workbench.action.terminal.selectDefaultShell',
DetachSession = 'workbench.action.terminal.detachSession',
CreateNew = 'workbench.action.terminal.new'
}
interface TerminalLabel {
name?: string,
@ -79,9 +85,6 @@ export class Terminal {
// Reset
await this.code.dispatchKeybinding('Backspace');
}
if (commandId === TerminalCommandIdWithValue.CreateNew) {
return await this._waitForTerminal(value);
}
await this.code.dispatchKeybinding(altKey ? 'Alt+Enter' : 'enter');
await this.quickinput.waitForQuickInputClosed();
}
@ -93,6 +96,11 @@ export class Terminal {
}
}
async createTerminal(assertLocation?: 'editor' | 'panel'): Promise<void> {
await this.runCommand(TerminalCommandId.CreateNew);
await this._waitForTerminal(assertLocation);
}
async assertEditorGroupCount(count: number): Promise<void> {
await this.code.waitForElements(Selector.EditorGroups, true, editorGroups => editorGroups && editorGroups.length === count);
}
@ -200,7 +208,7 @@ export class Terminal {
return (this.code.driver as any).page;
}
private async _waitForTerminal(value: any): Promise<void> {
private async _waitForTerminal(value?: 'editor' | 'panel'): Promise<void> {
await this.code.waitForElement(Selector.XtermFocused);
await this.code.waitForTerminalBuffer(value === 'editor' ? Selector.XtermEditor : Selector.Xterm, lines => lines.some(line => line.length > 0));
}

View file

@ -70,7 +70,7 @@ export function setup() {
await app.workbench.settingsEditor.addUserSetting('terminal.integrated.defaultLocation', '"editor"');
// Close the settings editor
await app.workbench.quickaccess.runCommand('workbench.action.closeAllEditors');
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew, 'editor');
await terminal.createTerminal('editor');
await terminal.assertEditorGroupCount(1);
await terminal.assertTerminalViewHidden();
});

View file

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Application, Terminal, TerminalCommandId, SettingsEditor } from '../../../../automation';
import { Application, Terminal, SettingsEditor } from '../../../../automation';
export function setup() {
describe('Terminal Input', () => {
@ -25,14 +25,14 @@ export function setup() {
}
it('should automatically reply to default "Terminate batch job (Y/N)"', async () => {
await terminal.runCommand(TerminalCommandId.CreateNew);
await terminal.createTerminal();
await writeTextForAutoReply('Terminate batch job (Y/N)?');
await terminal.waitForTerminalText(buffer => buffer.some(line => line.includes('Terminate batch job (Y/N)?Y')));
});
it('should automatically reply to a custom entry', async () => {
await settingsEditor.addUserSetting('terminal.integrated.autoReplies', '{ "foo": "bar" }');
await terminal.runCommand(TerminalCommandId.CreateNew);
await terminal.createTerminal();
await writeTextForAutoReply('foo');
await terminal.waitForTerminalText(buffer => buffer.some(line => line.includes('foobar')));
});

View file

@ -17,7 +17,7 @@ export function setup() {
describe('detach/attach', () => {
// https://github.com/microsoft/vscode/issues/137799
it.skip('should support basic reconnection', async () => {
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
await terminal.createTerminal();
// TODO: Handle passing in an actual regex, not string
await terminal.assertTerminalGroups([
[{ name: '.*' }]
@ -41,7 +41,7 @@ export function setup() {
});
it.skip('should persist buffer content', async () => {
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
await terminal.createTerminal();
// TODO: Handle passing in an actual regex, not string
await terminal.assertTerminalGroups([
[{ name: '.*' }]
@ -71,7 +71,7 @@ export function setup() {
// TODO: This is currently flaky because it takes time to send over the new icon to the backend
it.skip('should persist terminal icon', async () => {
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
await terminal.createTerminal();
// TODO: Handle passing in an actual regex, not string
await terminal.assertTerminalGroups([
[{ name: '.*' }]

View file

@ -24,7 +24,7 @@ export function setup() {
it.skip('should set the default profile to a contributed one', async () => {
await terminal.runCommandWithValue(TerminalCommandIdWithValue.SelectDefaultProfile, CONTRIBUTED_PROFILE_NAME);
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
await terminal.createTerminal();
await terminal.assertSingleTab({ name: CONTRIBUTED_PROFILE_NAME });
});
@ -37,7 +37,7 @@ export function setup() {
it('should set the default profile', async () => {
await terminal.runCommandWithValue(TerminalCommandIdWithValue.SelectDefaultProfile, process.platform === 'win32' ? 'PowerShell' : undefined);
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
await terminal.createTerminal();
await terminal.assertSingleTab({ name: ANY_PROFILE_NAME });
});

View file

@ -16,7 +16,7 @@ export function setup() {
it('clicking the plus button should create a terminal and display the tabs view showing no split decorations', async () => {
await terminal.runCommand(TerminalCommandId.Show);
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
await terminal.createTerminal();
await terminal.clickPlusButton();
await terminal.assertTerminalGroups([[{}], [{}]]);
});
@ -100,14 +100,14 @@ export function setup() {
it('should join tabs when more than one non-split terminal', async () => {
await terminal.runCommand(TerminalCommandId.Show);
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
await terminal.createTerminal();
await terminal.runCommand(TerminalCommandId.Join);
await terminal.assertTerminalGroups([[{}, {}]]);
});
it('should do nothing when unsplit tabs called with no splits', async () => {
await terminal.runCommand(TerminalCommandId.Show);
await terminal.runCommandWithValue(TerminalCommandIdWithValue.CreateNew);
await terminal.createTerminal();
await terminal.assertTerminalGroups([[{}], [{}]]);
await terminal.runCommand(TerminalCommandId.Unsplit);
await terminal.assertTerminalGroups([[{}], [{}]]);