Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompts/node/agent/test/terminalPrompt.spec.tsx
13406 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 { assert, suite, test } from 'vitest';
7
import { TerminalStatePromptElement } from '../../base/terminalState';
8
9
suite('TerminalStatePromptElement', () => {
10
const tasksService: any = {};
11
tasksService.getTerminalForTask = (task: any) => {
12
if (task.command === 'build') {
13
return { name: 'Terminal 3', processId: 3434, id: '3' };
14
} else if (task.command === 'watch') {
15
return { name: 'Terminal 4', processId: 5545, id: '4' };
16
}
17
return undefined;
18
};
19
test('Terminals', async () => {
20
const terminalService: any = {};
21
tasksService.getTasks = () => [[null, []]];
22
23
terminalService.terminals = [
24
{ name: 'Terminal 1', id: '1', processId: 1234 },
25
{ name: 'Terminal 2', id: '2', processId: 5678 },
26
{ name: 'Terminal 3', id: '3', processId: 3434 },
27
{ name: 'Terminal 4', id: '4', processId: 5545 },
28
];
29
terminalService.getLastCommandForTerminal = (term: { id: string }) => {
30
if (term.id === '1') {
31
return { commandLine: 'npm run build', cwd: '/workspace', exitCode: 0 };
32
} else if (term.id === '2') {
33
return { commandLine: 'npm test', cwd: '/workspace', exitCode: 1 };
34
}
35
return undefined;
36
};
37
38
const prompt = new TerminalStatePromptElement({}, tasksService, terminalService);
39
const rendered = await prompt.render();
40
41
const output = typeof rendered === 'string' ? rendered : JSON.stringify(rendered) ?? '';
42
assert(output.includes('Terminal 1'));
43
assert(output.includes('Terminal 2'));
44
});
45
});
46