Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/smoke/src/areas/terminal/terminal-stickyScroll.test.ts
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Application, Terminal, SettingsEditor, TerminalCommandIdWithValue } from '../../../../automation';
7
import { setTerminalTestSettings } from './terminal-helpers';
8
9
export function setup(options?: { skipSuite: boolean }) {
10
(options?.skipSuite ? describe.skip : describe)('Terminal stickyScroll', () => {
11
// Acquire automation API
12
let app: Application;
13
let terminal: Terminal;
14
let settingsEditor: SettingsEditor;
15
before(async function () {
16
app = this.app as Application;
17
terminal = app.workbench.terminal;
18
settingsEditor = app.workbench.settingsEditor;
19
await setTerminalTestSettings(app, [
20
['terminal.integrated.stickyScroll.enabled', 'true']
21
]);
22
});
23
24
after(async function () {
25
await settingsEditor.clearUserSettings();
26
});
27
28
// A polling approach is used to avoid test flakiness. While it's not ideal that this
29
// occurs, the main purpose of the tests is to verify sticky scroll shows and updates,
30
// not edge case race conditions on terminal start up
31
async function checkCommandAndOutput(
32
command: string,
33
exitCode: number,
34
prompt: string = 'Prompt> ',
35
expectedLineCount: number = 1
36
): Promise<void> {
37
const data = generateCommandAndOutput(prompt, command, exitCode);
38
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, data);
39
// Verify line count
40
await app.code.waitForElements('.terminal-sticky-scroll .xterm-rows > *', true, e => e.length === expectedLineCount);
41
// Verify content
42
const element = await app.code.getElement('.terminal-sticky-scroll .xterm-rows');
43
if (
44
element &&
45
// New lines don't come through in textContent
46
element.textContent.indexOf(`${prompt.replace(/\\r\\n/g, '')}${command}`) >= 0
47
) {
48
return;
49
}
50
throw new Error(`Failed for command ${command}, exitcode ${exitCode}, text content ${element?.textContent}`);
51
}
52
53
// Don't use beforeEach as that ignores the retry count, createEmptyTerminal has been
54
// flaky in the past
55
async function beforeEachSetup() {
56
// Create the simplest system profile to get as little process interaction as possible
57
await terminal.createEmptyTerminal();
58
}
59
60
it('should show sticky scroll when appropriate', async () => {
61
await beforeEachSetup();
62
63
// Write prompt, fill viewport, finish command, print new prompt, verify sticky scroll
64
await checkCommandAndOutput('sticky scroll 1', 0);
65
66
// And again with a failed command
67
await checkCommandAndOutput('sticky scroll 2', 1);
68
});
69
70
it('should support multi-line prompt', async () => {
71
await beforeEachSetup();
72
73
// Standard multi-line prompt
74
await checkCommandAndOutput('sticky scroll 1', 0, "Multi-line\\r\\nPrompt> ", 2);
75
76
// New line before prompt
77
await checkCommandAndOutput('sticky scroll 2', 0, "\\r\\nMulti-line Prompt> ", 1);
78
79
// New line before multi-line prompt
80
await checkCommandAndOutput('sticky scroll 3', 0, "\\r\\nMulti-line\\r\\nPrompt> ", 2);
81
});
82
});
83
}
84
85
function generateCommandAndOutput(prompt: string, command: string, exitCode: number): string {
86
return [
87
`${vsc('A')}${prompt}${vsc('B')}${command}`,
88
`\\r\\n${vsc('C')}`,
89
`\\r\\ndata`.repeat(50),
90
`\\r\\n${vsc(`D;${exitCode}`)}`,
91
].join('');
92
}
93
94
function vsc(data: string) {
95
return setTextParams(`633;${data}`);
96
}
97
98
function setTextParams(data: string) {
99
return osc(`${data}\\x07`);
100
}
101
102
function osc(data: string) {
103
return `\\x1b]${data}`;
104
}
105
106