Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CustomExecution2 test and make start fire after onDidOpenTerminal #77839

Merged
merged 5 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*---------------------------------------------------------------------------------------------
* 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 taskProvider = vscode.tasks.registerTaskProvider(taskType, {
provideTasks: () => {
const result: vscode.Task[] = [];
const kind: CustomTestingTaskDefinition = {
type: taskType,
customProp1: 'testing task one'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if the test code could demonstrate the use of the value of 'customProp1'.

When I used this in my project, I ended up creating some wrapper classes around the use of virtual terminal process and custom executions so I could get the custom execution data (the properties) back into the execution of the extension code in a seemingly clean way.

When the code is all in one test like this, the "capturing" works just fine, but when you do things like put your task definition in one file, execution of the code in another, etc. it becomes a bit cumbersome.

I can point you to what I ended up doing if you want.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be as easy as just adding an assertion somewhere?

};
const writeEmitter = new vscode.EventEmitter<string>();
const execution = new vscode.CustomExecution2((): Thenable<vscode.TerminalVirtualProcess> => {
return Promise.resolve(<vscode.TerminalVirtualProcess>{
onDidWrite: writeEmitter.event,
start: () => {
writeEmitter.fire('testing\r\n');
},
shutdown: () => {
taskProvider.dispose();
done();
}
});
});
const task = new vscode.Task2(kind, vscode.TaskScope.Workspace, taskName, taskType, execution);
result.push(task);
return result;
},
resolveTask(_task: vscode.Task): vscode.Task | undefined {
assert.fail('resolveTask should not trigger during the test');
return undefined;
Tyriar marked this conversation as resolved.
Show resolved Hide resolved
}
});
vscode.commands.executeCommand('workbench.action.tasks.runTask', `${taskType}: ${taskName}`);
});
});
});
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHostTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions src/vs/workbench/api/node/extHostTerminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
Expand Down Expand Up @@ -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.
Expand Down