Make task execution event tests more specific

This commit is contained in:
Alex Ross
2020-06-16 16:35:53 +02:00
parent 97a8ded3ba
commit 388da4e6f6

View File

@@ -138,35 +138,45 @@ import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomEx
commands.executeCommand('workbench.action.tasks.runTask', `${taskType}: ${taskName}`);
});
test('Execution from event is equal to original', () => {
test('Execution from onDidEndTaskProcess is equal to original', () => {
return new Promise(async (resolve, reject) => {
const task = new Task({ type: 'testTask' }, TaskScope.Workspace, 'echo', 'testTask', new ShellExecution('echo', ['hello test']));
const taskExecution = await tasks.executeTask(task);
let equalCount = 2;
function checkEqualCount() {
equalCount--;
if (equalCount === 0) {
resolve();
} else if (equalCount < 0) {
reject('Unexpected extra task events.');
}
}
tasks.onDidStartTaskProcess(e => {
if (e.execution === taskExecution) {
checkEqualCount();
} else {
disposables.push(tasks.onDidStartTaskProcess(e => {
if (e.execution !== taskExecution) {
reject('Unexpected task execution value in start process.');
}
});
}));
tasks.onDidEndTaskProcess(e => {
disposables.push(tasks.onDidEndTaskProcess(e => {
if (e.execution === taskExecution) {
checkEqualCount();
resolve();
} else {
reject('Unexpected task execution value in end process.');
}
});
}));
});
});
test('Execution from onDidStartTaskProcess is equal to original', () => {
return new Promise(async (resolve, reject) => {
const task = new Task({ type: 'testTask' }, TaskScope.Workspace, 'echo', 'testTask', new ShellExecution('echo', ['hello test']));
const taskExecution = await tasks.executeTask(task);
disposables.push(tasks.onDidStartTaskProcess(e => {
if (e.execution === taskExecution) {
resolve();
} else {
reject('Unexpected task execution value in start process.');
}
}));
disposables.push(tasks.onDidEndTaskProcess(e => {
if (e.execution !== taskExecution) {
reject('Unexpected task execution value in end process.');
}
}));
});
});
});