Path: blob/main/extensions/copilot/src/extension/prompts/node/agent/test/terminalPrompt.spec.tsx
13406 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { assert, suite, test } from 'vitest';6import { TerminalStatePromptElement } from '../../base/terminalState';78suite('TerminalStatePromptElement', () => {9const tasksService: any = {};10tasksService.getTerminalForTask = (task: any) => {11if (task.command === 'build') {12return { name: 'Terminal 3', processId: 3434, id: '3' };13} else if (task.command === 'watch') {14return { name: 'Terminal 4', processId: 5545, id: '4' };15}16return undefined;17};18test('Terminals', async () => {19const terminalService: any = {};20tasksService.getTasks = () => [[null, []]];2122terminalService.terminals = [23{ name: 'Terminal 1', id: '1', processId: 1234 },24{ name: 'Terminal 2', id: '2', processId: 5678 },25{ name: 'Terminal 3', id: '3', processId: 3434 },26{ name: 'Terminal 4', id: '4', processId: 5545 },27];28terminalService.getLastCommandForTerminal = (term: { id: string }) => {29if (term.id === '1') {30return { commandLine: 'npm run build', cwd: '/workspace', exitCode: 0 };31} else if (term.id === '2') {32return { commandLine: 'npm test', cwd: '/workspace', exitCode: 1 };33}34return undefined;35};3637const prompt = new TerminalStatePromptElement({}, tasksService, terminalService);38const rendered = await prompt.render();3940const output = typeof rendered === 'string' ? rendered : JSON.stringify(rendered) ?? '';41assert(output.includes('Terminal 1'));42assert(output.includes('Terminal 2'));43});44});4546