mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 09:08:53 +01:00
@@ -3,9 +3,6 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// todo@alexr00 https://github.com/microsoft/vscode/issues/141993
|
||||
/* eslint-disable no-async-promise-executor */
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { commands, ConfigurationTarget, CustomExecution, Disposable, env, Event, EventEmitter, Pseudoterminal, ShellExecution, Task, TaskDefinition, TaskExecution, TaskProcessStartEvent, tasks, TaskScope, Terminal, UIKind, window, workspace } from 'vscode';
|
||||
import { assertNoRpc } from '../utils';
|
||||
@@ -36,47 +33,49 @@ import { assertNoRpc } from '../utils';
|
||||
});
|
||||
|
||||
suite('ShellExecution', () => {
|
||||
test('Execution from onDidEndTaskProcess and onDidStartTaskProcess are equal to original', () => {
|
||||
return new Promise<void>(async (resolve) => {
|
||||
const task = new Task({ type: 'testTask' }, TaskScope.Workspace, 'echo', 'testTask', new ShellExecution('echo', ['hello test']));
|
||||
let taskExecution: TaskExecution | undefined;
|
||||
const executeDoneEvent: EventEmitter<void> = new EventEmitter();
|
||||
const taskExecutionShouldBeSet: Promise<void> = new Promise(resolve => {
|
||||
const disposable = executeDoneEvent.event(() => {
|
||||
resolve();
|
||||
disposable.dispose();
|
||||
});
|
||||
test('Execution from onDidEndTaskProcess and onDidStartTaskProcess are equal to original', async () => {
|
||||
const executeDoneEvent: EventEmitter<void> = new EventEmitter();
|
||||
const taskExecutionShouldBeSet: Promise<void> = new Promise(resolve => {
|
||||
const disposable = executeDoneEvent.event(() => {
|
||||
resolve();
|
||||
disposable.dispose();
|
||||
});
|
||||
let count = 2;
|
||||
const progressMade: EventEmitter<void> = new EventEmitter();
|
||||
let startSucceeded = false;
|
||||
let endSucceeded = false;
|
||||
});
|
||||
|
||||
const progressMade: EventEmitter<void> = new EventEmitter();
|
||||
let count = 2;
|
||||
let startSucceeded = false;
|
||||
let endSucceeded = false;
|
||||
const testDonePromise = new Promise<void>(resolve => {
|
||||
disposables.push(progressMade.event(() => {
|
||||
count--;
|
||||
if ((count === 0) && startSucceeded && endSucceeded) {
|
||||
resolve();
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
disposables.push(tasks.onDidStartTaskProcess(async (e) => {
|
||||
await taskExecutionShouldBeSet;
|
||||
if (e.execution === taskExecution) {
|
||||
startSucceeded = true;
|
||||
progressMade.fire();
|
||||
}
|
||||
}));
|
||||
|
||||
disposables.push(tasks.onDidEndTaskProcess(async (e) => {
|
||||
await taskExecutionShouldBeSet;
|
||||
if (e.execution === taskExecution) {
|
||||
endSucceeded = true;
|
||||
progressMade.fire();
|
||||
}
|
||||
}));
|
||||
taskExecution = await tasks.executeTask(task);
|
||||
executeDoneEvent.fire();
|
||||
});
|
||||
|
||||
const task = new Task({ type: 'testTask' }, TaskScope.Workspace, 'echo', 'testTask', new ShellExecution('echo', ['hello test']));
|
||||
let taskExecution: TaskExecution | undefined;
|
||||
|
||||
disposables.push(tasks.onDidStartTaskProcess(async (e) => {
|
||||
await taskExecutionShouldBeSet;
|
||||
if (e.execution === taskExecution) {
|
||||
startSucceeded = true;
|
||||
progressMade.fire();
|
||||
}
|
||||
}));
|
||||
|
||||
disposables.push(tasks.onDidEndTaskProcess(async (e) => {
|
||||
await taskExecutionShouldBeSet;
|
||||
if (e.execution === taskExecution) {
|
||||
endSucceeded = true;
|
||||
progressMade.fire();
|
||||
}
|
||||
}));
|
||||
taskExecution = await tasks.executeTask(task);
|
||||
executeDoneEvent.fire();
|
||||
await testDonePromise;
|
||||
});
|
||||
|
||||
test('dependsOn task should start with a different processId (#118256)', async () => {
|
||||
@@ -297,86 +296,93 @@ import { assertNoRpc } from '../utils';
|
||||
});
|
||||
});
|
||||
|
||||
test('A task can be fetched and executed (#100577)', () => {
|
||||
return new Promise<void>(async (resolve, reject) => {
|
||||
class CustomTerminal implements Pseudoterminal {
|
||||
private readonly writeEmitter = new EventEmitter<string>();
|
||||
public readonly onDidWrite: Event<string> = this.writeEmitter.event;
|
||||
public async close(): Promise<void> { }
|
||||
private closeEmitter = new EventEmitter<void>();
|
||||
onDidClose: Event<void> = this.closeEmitter.event;
|
||||
public open(): void {
|
||||
this.closeEmitter.fire();
|
||||
resolve();
|
||||
}
|
||||
test('A task can be fetched and executed (#100577)', async () => {
|
||||
class CustomTerminal implements Pseudoterminal {
|
||||
private readonly writeEmitter = new EventEmitter<string>();
|
||||
public readonly onDidWrite: Event<string> = this.writeEmitter.event;
|
||||
public async close(): Promise<void> { }
|
||||
private closeEmitter = new EventEmitter<void>();
|
||||
onDidClose: Event<void> = this.closeEmitter.event;
|
||||
private readonly _onDidOpen = new EventEmitter<void>();
|
||||
public readonly onDidOpen = this._onDidOpen.event;
|
||||
public open(): void {
|
||||
this._onDidOpen.fire();
|
||||
this.closeEmitter.fire();
|
||||
}
|
||||
}
|
||||
|
||||
function buildTask(): Task {
|
||||
const task = new Task(
|
||||
{
|
||||
type: 'customTesting',
|
||||
},
|
||||
TaskScope.Workspace,
|
||||
'Test Task',
|
||||
'customTesting',
|
||||
new CustomExecution(
|
||||
async (): Promise<Pseudoterminal> => {
|
||||
return new CustomTerminal();
|
||||
}
|
||||
)
|
||||
);
|
||||
return task;
|
||||
}
|
||||
|
||||
disposables.push(tasks.registerTaskProvider('customTesting', {
|
||||
provideTasks: () => {
|
||||
return [buildTask()];
|
||||
},
|
||||
resolveTask(_task: Task): undefined {
|
||||
return undefined;
|
||||
}
|
||||
}));
|
||||
|
||||
const task = await tasks.fetchTasks({ type: 'customTesting' });
|
||||
|
||||
if (task && task.length > 0) {
|
||||
await tasks.executeTask(task[0]);
|
||||
} else {
|
||||
reject('fetched task can\'t be undefined');
|
||||
}
|
||||
const customTerminal = new CustomTerminal();
|
||||
const terminalOpenedPromise = new Promise<void>(resolve => {
|
||||
const disposable = customTerminal.onDidOpen(() => {
|
||||
disposable.dispose();
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
function buildTask(): Task {
|
||||
const task = new Task(
|
||||
{
|
||||
type: 'customTesting',
|
||||
},
|
||||
TaskScope.Workspace,
|
||||
'Test Task',
|
||||
'customTesting',
|
||||
new CustomExecution(
|
||||
async (): Promise<Pseudoterminal> => {
|
||||
return customTerminal;
|
||||
}
|
||||
)
|
||||
);
|
||||
return task;
|
||||
}
|
||||
|
||||
disposables.push(tasks.registerTaskProvider('customTesting', {
|
||||
provideTasks: () => {
|
||||
return [buildTask()];
|
||||
},
|
||||
resolveTask(_task: Task): undefined {
|
||||
return undefined;
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
const task = await tasks.fetchTasks({ type: 'customTesting' });
|
||||
|
||||
if (task && task.length > 0) {
|
||||
await tasks.executeTask(task[0]);
|
||||
} else {
|
||||
assert.fail('fetched task can\'t be undefined');
|
||||
}
|
||||
await terminalOpenedPromise;
|
||||
});
|
||||
|
||||
test('A task can be fetched with default task group information', () => {
|
||||
return new Promise<void>(async (resolve, reject) => {
|
||||
// Add default to tasks.json since this is not possible using an API yet.
|
||||
const tasksConfig = workspace.getConfiguration('tasks');
|
||||
await tasksConfig.update('version', '2.0.0', ConfigurationTarget.Workspace);
|
||||
await tasksConfig.update('tasks', [
|
||||
{
|
||||
label: 'Run this task',
|
||||
type: 'shell',
|
||||
command: 'sleep 1',
|
||||
problemMatcher: [],
|
||||
group: {
|
||||
kind: 'build',
|
||||
isDefault: 'true'
|
||||
}
|
||||
test('A task can be fetched with default task group information', async () => {
|
||||
// Add default to tasks.json since this is not possible using an API yet.
|
||||
const tasksConfig = workspace.getConfiguration('tasks');
|
||||
await tasksConfig.update('version', '2.0.0', ConfigurationTarget.Workspace);
|
||||
await tasksConfig.update('tasks', [
|
||||
{
|
||||
label: 'Run this task',
|
||||
type: 'shell',
|
||||
command: 'sleep 1',
|
||||
problemMatcher: [],
|
||||
group: {
|
||||
kind: 'build',
|
||||
isDefault: 'true'
|
||||
}
|
||||
], ConfigurationTarget.Workspace);
|
||||
|
||||
const task = <Task[]>(await tasks.fetchTasks());
|
||||
|
||||
if (task && task.length > 0) {
|
||||
const grp = task[0].group;
|
||||
assert.strictEqual(grp?.isDefault, true);
|
||||
resolve();
|
||||
} else {
|
||||
reject('fetched task can\'t be undefined');
|
||||
}
|
||||
// Reset tasks.json
|
||||
await tasksConfig.update('tasks', []);
|
||||
});
|
||||
], ConfigurationTarget.Workspace);
|
||||
|
||||
const task = <Task[]>(await tasks.fetchTasks());
|
||||
|
||||
if (task && task.length > 0) {
|
||||
const grp = task[0].group;
|
||||
assert.strictEqual(grp?.isDefault, true);
|
||||
} else {
|
||||
assert.fail('fetched task can\'t be undefined');
|
||||
}
|
||||
// Reset tasks.json
|
||||
await tasksConfig.update('tasks', []);
|
||||
});
|
||||
|
||||
test('Tasks can be run back to back', async () => {
|
||||
|
||||
Reference in New Issue
Block a user