Skip to content

Commit 388da4e

Browse files
committed
Make task execution event tests more specific
1 parent 97a8ded commit 388da4e

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

extensions/vscode-api-tests/src/singlefolder-tests/workspace.tasks.test.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,35 +138,45 @@ import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomEx
138138
commands.executeCommand('workbench.action.tasks.runTask', `${taskType}: ${taskName}`);
139139
});
140140

141-
test('Execution from event is equal to original', () => {
141+
test('Execution from onDidEndTaskProcess is equal to original', () => {
142142
return new Promise(async (resolve, reject) => {
143143
const task = new Task({ type: 'testTask' }, TaskScope.Workspace, 'echo', 'testTask', new ShellExecution('echo', ['hello test']));
144144
const taskExecution = await tasks.executeTask(task);
145-
let equalCount = 2;
146-
function checkEqualCount() {
147-
equalCount--;
148-
if (equalCount === 0) {
149-
resolve();
150-
} else if (equalCount < 0) {
151-
reject('Unexpected extra task events.');
145+
146+
disposables.push(tasks.onDidStartTaskProcess(e => {
147+
if (e.execution !== taskExecution) {
148+
reject('Unexpected task execution value in start process.');
152149
}
153-
}
150+
}));
154151

155-
tasks.onDidStartTaskProcess(e => {
152+
disposables.push(tasks.onDidEndTaskProcess(e => {
156153
if (e.execution === taskExecution) {
157-
checkEqualCount();
154+
resolve();
158155
} else {
159-
reject('Unexpected task execution value in start process.');
156+
reject('Unexpected task execution value in end process.');
160157
}
161-
});
158+
}));
159+
});
160+
});
162161

163-
tasks.onDidEndTaskProcess(e => {
162+
test('Execution from onDidStartTaskProcess is equal to original', () => {
163+
return new Promise(async (resolve, reject) => {
164+
const task = new Task({ type: 'testTask' }, TaskScope.Workspace, 'echo', 'testTask', new ShellExecution('echo', ['hello test']));
165+
const taskExecution = await tasks.executeTask(task);
166+
167+
disposables.push(tasks.onDidStartTaskProcess(e => {
164168
if (e.execution === taskExecution) {
165-
checkEqualCount();
169+
resolve();
166170
} else {
171+
reject('Unexpected task execution value in start process.');
172+
}
173+
}));
174+
175+
disposables.push(tasks.onDidEndTaskProcess(e => {
176+
if (e.execution !== taskExecution) {
167177
reject('Unexpected task execution value in end process.');
168178
}
169-
});
179+
}));
170180
});
171181
});
172182
});

0 commit comments

Comments
 (0)