Add some detach/attach tests

This commit is contained in:
Daniel Imms 2021-11-19 10:33:43 -08:00
parent 4f87975515
commit 5dec5256d7
6 changed files with 115 additions and 24 deletions

View file

@ -158,7 +158,7 @@ export abstract class BaseWindowDriver implements IWindowDriver {
throw new Error(`Xterm not found: ${selector}`);
}
xterm._core._coreService.triggerDataEvent(text);
xterm._core.coreService.triggerDataEvent(text);
}
getLocaleInfo(): Promise<ILocaleInfo> {

View file

@ -20,7 +20,7 @@ export interface IXtermCore {
height: number;
};
_coreService: {
coreService: {
triggerDataEvent(data: string, wasUserInput?: boolean): void;
};

View file

@ -26,7 +26,8 @@ export enum TerminalCommandIdWithValue {
ChangeColor = 'workbench.action.terminal.changeColor',
ChangeIcon = 'workbench.action.terminal.changeIcon',
NewWithProfile = 'workbench.action.terminal.newWithProfile',
SelectDefaultProfile = 'workbench.action.terminal.selectDefaultShell'
SelectDefaultProfile = 'workbench.action.terminal.selectDefaultShell',
AttachToSession = 'workbench.action.terminal.attachToSession',
}
export enum TerminalCommandId {
@ -41,7 +42,8 @@ export enum TerminalCommandId {
MoveToPanel = 'workbench.action.terminal.moveToTerminalPanel',
MoveToEditor = 'workbench.action.terminal.moveToEditor',
NewWithProfile = 'workbench.action.terminal.newWithProfile',
SelectDefaultProfile = 'workbench.action.terminal.selectDefaultShell'
SelectDefaultProfile = 'workbench.action.terminal.selectDefaultShell',
DetachSession = 'workbench.action.terminal.detachSession',
}
interface TerminalLabel {
name?: string,
@ -108,6 +110,27 @@ export class Terminal {
}
}
async getTerminalGroups(): Promise<TerminalGroup[]> {
const tabCount = (await this.code.waitForElements(Selector.Tabs, true)).length;
console.log('tabCount', tabCount);
const groups: TerminalGroup[] = [];
for (let i = 0; i < tabCount; i++) {
const instance = await this.code.waitForElement(`${Selector.Tabs}[data-index="${i}"] ${Selector.TabsEntry}`);
console.log('instance', instance);
const label: TerminalLabel = {
name: instance.textContent.replace(/^[├┌└]\s*/, '')
};
// It's a new group if the the tab does not start with ├ or └
if (instance.textContent.match(/^[├└]/)) {
groups[groups.length - 1].push(label);
} else {
groups.push([label]);
}
}
console.log('groups', groups);
return groups;
}
private async assertTabExpected(selector?: string, listIndex?: number, nameRegex?: RegExp, icon?: string, color?: string): Promise<void> {
if (listIndex) {
if (nameRegex) {
@ -132,6 +155,10 @@ export class Terminal {
}
}
async assertTerminalViewHidden(): Promise<void> {
await this.code.waitForElement(Selector.TerminalView, result => result === undefined);
}
async clickPlusButton(): Promise<void> {
await this.code.waitAndClick(Selector.PlusButton);
}

View file

@ -0,0 +1,82 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ok, strictEqual } from 'assert';
import { ParsedArgs } from 'minimist';
import { Application, Terminal, TerminalCommandId, TerminalCommandIdWithValue } from '../../../../automation/out';
import { afterSuite, beforeSuite } from '../../utils';
export function setup(opts: ParsedArgs) {
describe.only('Terminal Persistence', () => {
let terminal: Terminal;
beforeSuite(opts);
afterSuite(opts);
before(async function () {
const app = this.app as Application;
terminal = app.workbench.terminal;
// Always show tabs to make getting terminal groups easier
await app.workbench.settingsEditor.addUserSetting('terminal.integrated.tabs.hideCondition', '"never"');
await app.workbench.quickaccess.runCommand('workbench.action.closeAllEditors');
});
afterEach(async () => {
await terminal.runCommand(TerminalCommandId.KillAll);
});
describe('detach/attach', () => {
it('should support basic reconnection', async () => {
await terminal.runCommand(TerminalCommandId.CreateNew);
// TODO: Handle passing in an actual regex, not string
await terminal.assertTerminalGroups([
[{ name: '.*' }]
]);
const groups = await terminal.getTerminalGroups();
strictEqual(groups.length, 1);
strictEqual(groups[0].length, 1);
ok(groups[0][0].name!.length > 0);
const detachedName = groups[0][0].name!;
console.log('detached name', detachedName);
await terminal.runCommand(TerminalCommandId.DetachSession);
await terminal.assertTerminalViewHidden();
await terminal.runCommandWithValue(TerminalCommandIdWithValue.AttachToSession, detachedName);
await terminal.assertTerminalGroups([
[{ name: detachedName }]
]);
});
it('should persist buffer content', async () => {
await terminal.runCommand(TerminalCommandId.CreateNew);
// TODO: Handle passing in an actual regex, not string
await terminal.assertTerminalGroups([
[{ name: '.*' }]
]);
const groups = await terminal.getTerminalGroups();
strictEqual(groups.length, 1);
strictEqual(groups[0].length, 1);
ok(groups[0][0].name!.length > 0);
const detachedName = groups[0][0].name!;
await terminal.runCommandInTerminal('echo terminal_test_content');
await terminal.waitForTerminalText(buffer => buffer.some(e => e.includes('terminal_test_content')));
await terminal.runCommand(TerminalCommandId.DetachSession);
await terminal.assertTerminalViewHidden();
await terminal.runCommandWithValue(TerminalCommandIdWithValue.AttachToSession, detachedName);
await terminal.assertTerminalGroups([
[{ name: detachedName }]
]);
await terminal.waitForTerminalText(buffer => buffer.some(e => e.includes('terminal_test_content')));
});
});
});
}

View file

@ -1,20 +0,0 @@
/*---------------------------------------------------------------------------------------------
* 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 { Application } from '../../../../automation';
import { afterSuite, beforeSuite } from '../../utils';
export function setup(opts: ParsedArgs) {
describe('Terminal Reconnection', () => {
beforeSuite(opts);
afterSuite(opts);
it.skip('should reconnect to a single terminal on reload', async () => {
const app = this.app as Application;
console.log(app);
});
});
}

View file

@ -30,6 +30,7 @@ import { setup as setupLaunchTests } from './areas/workbench/launch.test';
import { setup as setupTerminalProfileTests } from './areas/terminal/terminal-profiles.test';
import { setup as setupTerminalTabsTests } from './areas/terminal/terminal-tabs.test';
import { setup as setupTerminalEditorsTests } from './areas/terminal/terminal-editors.test';
import { setup as setupTerminalPersistenceTests } from './areas/terminal/terminal-persistence.test';
const testDataPath = path.join(os.tmpdir(), 'vscsmoke');
if (fs.existsSync(testDataPath)) {
@ -364,4 +365,5 @@ describe(`VSCode Smoke Tests (${opts.web ? 'Web' : 'Electron'})`, () => {
if (opts.web) { setupTerminalProfileTests(opts); }
if (opts.web) { setupTerminalTabsTests(opts); }
if (opts.web) { setupTerminalEditorsTests(opts); }
if (opts.web) { setupTerminalPersistenceTests(opts); }
});