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

Test CustomExecution callback tasks #71089

Closed
2 tasks done
alexr00 opened this issue Mar 25, 2019 · 0 comments
Closed
2 tasks done

Test CustomExecution callback tasks #71089

alexr00 opened this issue Mar 25, 2019 · 0 comments

Comments

@alexr00
Copy link
Member

alexr00 commented Mar 25, 2019

Refs: #66818

Complexity: 4

With the addition of the CustomExecution task type, extensions can now contribute tasks that are run as callbacks from VS Code, instead of tasks that run as a script or a process. Using the below code as a starting point, create an extension that uses the CustomExecution type to contribute tasks. Things to test:

  • Contribute multiple tasks. Test that they all get executed correctly.
  • Contribute multiple tasks, and make only some of them have a CustomExecution. The others can have a ShellExecution type. (example: let execution = new vscode.ShellExecution("echo hello");).
  • Test that you can use the TerminalRenderer from within the CustomExecution to send text to the terminal and to read from the terminal using write and onDidAcceptInput.
  • Configure a task that has a CustomExecution in tasks.json. Try setting various presentation properties and other properties(dependsOn, label, group, problemMatcher, etc.) and test that they all behave correctly. Add other properties to CustomTestingTaskDefinition and in the package.json and test that the right task is modified when you configure it in tasks.json. How to refer to the task from tasks.json
        {
            "type": "customTesting",
            "customProp1": "testing task one",
            // try using dependsOn, presentation, and other task configuration properties
        }
  • Try returning different exit codes from the CustomExecution. 0 is success, anything else is not. Test that when the exit code is non-zero and ”presentation:{ “reveal”:”silent”} that the terminal is shown when the task completes.
  • Test that the Rerun Last Task command works with CustomExecution tasks.
  • Try setting a custom task as the preLaunchTask in a launch configuration and test that launch configuration still works.
  • Test that a ”type”:”shell” task in tasks.json can depend on a contributed CustomExecution task.

To start with this sample code, copy vscode.proposed.d.ts into your extension and add to your package.json:

"enableProposedApi": true,
"contributes": {
	"taskDefinitions": [
		{
			"type": "customTesting",
			"required": [
				"customProp1"
			],
			"properties": {
				"customProp1": {
					"type": "string",
					"description": "The first custom task property"
				}
			}
		}
	]
},

Sample code:

let taskProvider: vscode.Disposable | undefined;
const taskType: string = "customTesting";

export function activate(_context: vscode.ExtensionContext): void {
	let rakePromise: Thenable<vscode.Task[]> | undefined = undefined;
	
	taskProvider = vscode.tasks.registerTaskProvider(taskType, {
		provideTasks: () => {
			rakePromise = getSomeTasks();
			return rakePromise;
		},
		resolveTask(_task: vscode.Task): vscode.Task | undefined {
			// Don't worry about testing anything with resolve task. It is old API that was never implemented.
			return undefined;
		}
	});
}

export function deactivate(): void {
	if (taskProvider) {
		taskProvider.dispose();
	}
}

interface CustomTestingTaskDefinition extends vscode.TaskDefinition {
	/**
	 * One of the task properties. This can be used to customize the task in the tasks.json
	 */
	customProp1: string;
}

async function getSomeTasks(): Promise<vscode.Task[]> {
	let result: vscode.Task[] = [];

	let kind: CustomTestingTaskDefinition = {
		type: taskType,
		customProp1: "testing task one"
	};
	let execution = new vscode.CustomExecution((terminalRenderer, cancellationToken, args): Thenable<number> => {
		return new Promise<number>(resolve => {
			// This is the custom task callback!
			resolve(0);
		});
	});
	const taskName = "First custom task";
	let task = new vscode.Task2(kind, vscode.TaskScope.Workspace, taskName, taskType, execution);
	result.push(task);
	return result;
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants