1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Application, Terminal, SettingsEditor, TerminalCommandIdWithValue, TerminalCommandId } from '../../../../automation';
import { setTerminalTestSettings } from './terminal-helpers';
export function setup() {
describe('Terminal Shell Integration', () => {
let terminal: Terminal;
let settingsEditor: SettingsEditor;
let app: Application;
// Acquire automation API
before(async function () {
app = this.app as Application;
terminal = app.workbench.terminal;
settingsEditor = app.workbench.settingsEditor;
});
afterEach(async function () {
await app.workbench.terminal.runCommand(TerminalCommandId.KillAll);
});
async function createShellIntegrationProfile() {
await terminal.runCommandWithValue(TerminalCommandIdWithValue.NewWithProfile, process.platform === 'win32' ? 'PowerShell' : 'bash');
}
// TODO: Some agents may not have pwsh installed?
(process.platform === 'win32' ? describe.skip : describe)(`Process-based tests`, function () {
before(async function () {
await setTerminalTestSettings(app, [['terminal.integrated.shellIntegration.enabled', 'true']]);
});
after(async function () {
await settingsEditor.clearUserSettings();
});
describe('Decorations', function () {
describe('Should show default icons', function () {
it('Placeholder', async () => {
await createShellIntegrationProfile();
await terminal.assertCommandDecorations({ placeholder: 1, success: 0, error: 0 });
});
it('Success', async () => {
await createShellIntegrationProfile();
await terminal.runCommandInTerminal(`echo "success"`);
await terminal.assertCommandDecorations({ placeholder: 1, success: 1, error: 0 });
});
it('Error', async () => {
await createShellIntegrationProfile();
await terminal.runCommandInTerminal(`false`);
await terminal.assertCommandDecorations({ placeholder: 1, success: 0, error: 1 });
});
});
describe('Custom configuration', function () {
it('Should update and show custom icons', async () => {
await createShellIntegrationProfile();
await terminal.assertCommandDecorations({ placeholder: 1, success: 0, error: 0 });
await terminal.runCommandInTerminal(`echo "foo"`);
await terminal.runCommandInTerminal(`bar`);
await settingsEditor.addUserSetting('terminal.integrated.shellIntegration.decorationIcon', '"zap"');
await settingsEditor.addUserSetting('terminal.integrated.shellIntegration.decorationIconSuccess', '"zap"');
await settingsEditor.addUserSetting('terminal.integrated.shellIntegration.decorationIconError', '"zap"');
await terminal.assertCommandDecorations(undefined, { updatedIcon: "zap", count: 3 });
await app.workbench.terminal.runCommand(TerminalCommandId.KillAll);
});
});
});
});
// These are integration tests that only test the UI side by simulating process writes.
// Because of this, they do not test the shell integration scripts, only what the scripts
// are expected to write.
describe('Write data-based tests', () => {
before(async function () {
await setTerminalTestSettings(app);
});
after(async function () {
await settingsEditor.clearUserSettings();
});
beforeEach(async function () {
// 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')}`);
});
describe('VS Code sequences', () => {
it('should handle the simple case', async () => {
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `${vsc('A')}Prompt> ${vsc('B')}exitcode 0`);
await terminal.assertCommandDecorations({ placeholder: 1, success: 0, error: 0 });
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `\\r\\n${vsc('C')}Success\\r\\n${vsc('D;0')}`);
await terminal.assertCommandDecorations({ placeholder: 0, success: 1, error: 0 });
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `${vsc('A')}Prompt> ${vsc('B')}exitcode 1`);
await terminal.assertCommandDecorations({ placeholder: 1, success: 1, error: 0 });
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `\\r\\n${vsc('C')}Failure\\r\\n${vsc('D;1')}`);
await terminal.assertCommandDecorations({ placeholder: 0, success: 1, error: 1 });
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `${vsc('A')}Prompt> ${vsc('B')}`);
await terminal.assertCommandDecorations({ placeholder: 1, success: 1, error: 1 });
});
});
// TODO: This depends on https://github.com/microsoft/vscode/issues/146587
describe.skip('Final Term sequences', () => {
it('should handle the simple case', async () => {
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `${ft('A')}Prompt> ${ft('B')}exitcode 0`);
await terminal.assertCommandDecorations({ placeholder: 1, success: 0, error: 0 });
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `\\r\\n${ft('C')}Success\\r\\n${ft('D;0')}`);
await terminal.assertCommandDecorations({ placeholder: 0, success: 1, error: 0 });
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `${ft('A')}Prompt> ${ft('B')}exitcode 1`);
await terminal.assertCommandDecorations({ placeholder: 1, success: 1, error: 0 });
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `\\r\\n${ft('C')}Failure\\r\\n${ft('D;1')}`);
await terminal.assertCommandDecorations({ placeholder: 0, success: 1, error: 1 });
await terminal.runCommandWithValue(TerminalCommandIdWithValue.WriteDataToTerminal, `${ft('A')}Prompt> ${ft('B')}exitcode 1`);
await terminal.assertCommandDecorations({ placeholder: 1, success: 1, error: 1 });
});
});
});
});
}
function ft(data: string) {
return setTextParams(`133;${data}`);
}
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}`;
}
|