Make empty terminal smoke test technique reusable

This commit is contained in:
Daniel Imms 2023-11-08 07:16:24 -08:00
parent bd2d20551d
commit bff9161987
No known key found for this signature in database
GPG key ID: E5CF412B63651C69
2 changed files with 34 additions and 13 deletions

View file

@ -142,6 +142,23 @@ export class Terminal {
await this._waitForTerminal(expectedLocation);
}
/**
* Creates an empty terminal by opening a regular terminal and resetting its state such that it
* essentially acts like an Pseudoterminal extension API-based terminal. This can then be paired
* with `TerminalCommandIdWithValue.WriteDataToTerminal` to make more reliable tests.
*/
async createEmptyTerminal(expectedLocation?: 'editor' | 'panel'): Promise<void> {
await this.createTerminal(expectedLocation);
// Erase all content and reset cursor to top
await this.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `${csi('2J')}${csi('H')}`);
// Force windows pty mode off; assume all sequences are rendered in correct position
if (process.platform === 'win32') {
await this.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `${vsc('P;IsWindows=False')}`);
}
}
async assertEditorGroupCount(count: number): Promise<void> {
await this.code.waitForElements(Selector.EditorGroups, true, editorGroups => editorGroups && editorGroups.length === count);
}
@ -289,3 +306,19 @@ export class Terminal {
await this.code.waitForTerminalBuffer(expectedLocation === 'editor' ? Selector.XtermEditor : Selector.Xterm, lines => lines.some(line => line.length > 0));
}
}
function vsc(data: string) {
return setTextParams(`633;${data}`);
}
function setTextParams(data: string) {
return osc(`${data}\\x07`);
}
function osc(data: string) {
return `\\x1b]${data}`;
}
function csi(data: string) {
return `\\x1b[${data}`;
}

View file

@ -27,15 +27,7 @@ export function setup() {
it('should show sticky scroll when appropriate', async () => {
// Create the simplest system profile to get as little process interaction as possible
await terminal.createTerminal();
// Erase all content and reset cursor to top
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `${csi('2J')}${csi('H')}`);
// Force windows pty mode off; assume all sequences are rendered in correct position
if (process.platform === 'win32') {
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `${vsc('P;IsWindows=False')}`);
}
await terminal.createEmptyTerminal();
// Write prompt, fill viewport, finish command
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `${vsc('A')}Prompt> ${vsc('B')}sticky scroll 1`);
@ -71,7 +63,3 @@ function setTextParams(data: string) {
function osc(data: string) {
return `\\x1b]${data}`;
}
function csi(data: string) {
return `\\x1b[${data}`;
}