mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
Create CustomExecution2 test, make start fire after onDidOpenTerminal
Part of #70978
This commit is contained in:
parent
df5d748fe5
commit
9d43802fd4
|
@ -0,0 +1,63 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
suite.only('workspace-namespace', () => {
|
||||
|
||||
suite('Tasks', () => {
|
||||
|
||||
test('CustomExecution2 task should start and shutdown successfully', (done) => {
|
||||
interface CustomTestingTaskDefinition extends vscode.TaskDefinition {
|
||||
/**
|
||||
* One of the task properties. This can be used to customize the task in the tasks.json
|
||||
*/
|
||||
customProp1: string;
|
||||
}
|
||||
const taskType: string = 'customTesting';
|
||||
const taskName = 'First custom task';
|
||||
const reg1 = vscode.window.onDidOpenTerminal(term => {
|
||||
reg1.dispose();
|
||||
const reg2 = term.onDidWriteData(e => {
|
||||
reg2.dispose();
|
||||
assert.equal(e, 'testing\r\n');
|
||||
term.dispose();
|
||||
});
|
||||
});
|
||||
const exitEmitter = new vscode.EventEmitter<number>();
|
||||
const taskProvider = vscode.tasks.registerTaskProvider(taskType, {
|
||||
provideTasks: () => {
|
||||
let result: vscode.Task[] = [];
|
||||
let kind: CustomTestingTaskDefinition = {
|
||||
type: taskType,
|
||||
customProp1: 'testing task one'
|
||||
};
|
||||
const writeEmitter = new vscode.EventEmitter<string>();
|
||||
let execution = new vscode.CustomExecution2((): Thenable<vscode.TerminalVirtualProcess> => {
|
||||
return Promise.resolve(<vscode.TerminalVirtualProcess>{
|
||||
onDidWrite: writeEmitter.event,
|
||||
start: () => {
|
||||
writeEmitter.fire('testing\r\n');
|
||||
},
|
||||
onDidExit: exitEmitter.event,
|
||||
shutdown: () => {
|
||||
taskProvider.dispose();
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
let task = new vscode.Task2(kind, vscode.TaskScope.Workspace, taskName, taskType, execution);
|
||||
result.push(task);
|
||||
return result;
|
||||
},
|
||||
resolveTask(_task: vscode.Task): vscode.Task | undefined {
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
vscode.commands.executeCommand('workbench.action.tasks.runTask', `${taskType}: ${taskName}`);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -588,7 +588,7 @@ export class ExtHostTask implements ExtHostTaskShape {
|
|||
|
||||
// Clone the custom execution to keep the original untouched. This is important for multiple runs of the same task.
|
||||
this._activeCustomExecutions2.set(execution.id, execution2);
|
||||
this._terminalService.attachVirtualProcessToTerminal(terminalId, await execution2.callback());
|
||||
await this._terminalService.attachVirtualProcessToTerminal(terminalId, await execution2.callback());
|
||||
}
|
||||
|
||||
// Once a terminal is spun up for the custom execution task this event will be fired.
|
||||
|
|
|
@ -337,8 +337,8 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
|
|||
return terminal;
|
||||
}
|
||||
|
||||
public attachVirtualProcessToTerminal(id: number, virtualProcess: vscode.TerminalVirtualProcess) {
|
||||
const terminal = this._getTerminalById(id);
|
||||
public async attachVirtualProcessToTerminal(id: number, virtualProcess: vscode.TerminalVirtualProcess): Promise<void> {
|
||||
const terminal = this._getTerminalByIdEventually(id);
|
||||
if (!terminal) {
|
||||
throw new Error(`Cannot resolve terminal with id ${id} for virtual process`);
|
||||
}
|
||||
|
@ -619,6 +619,10 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
|
|||
}
|
||||
|
||||
public async $startVirtualProcess(id: number, initialDimensions: ITerminalDimensionsDto | undefined): Promise<void> {
|
||||
// Make sure the ExtHostTerminal exists so onDidOpenTerminal has fired before we call
|
||||
// TerminalVirtualProcess.start
|
||||
await this._getTerminalByIdEventually(id);
|
||||
|
||||
// Processes should be initialized here for normal virtual process terminals, however for
|
||||
// tasks they are responsible for attaching the virtual process to a terminal so this
|
||||
// function may be called before tasks is able to attach to the terminal.
|
||||
|
|
Loading…
Reference in a new issue