Skip to content

Commit ae245c9

Browse files
committed
Fix onDidStart and End task test
1 parent 15ada62 commit ae245c9

File tree

1 file changed

+15
-45
lines changed

1 file changed

+15
-45
lines changed

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

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomEx
167167
commands.executeCommand('workbench.action.tasks.runTask', `${taskType}: ${taskName}`);
168168
});
169169

170-
test.skip('Execution from onDidEndTaskProcess is equal to original', () => {
171-
return new Promise(async (resolve, reject) => {
170+
test('Execution from onDidEndTaskProcess and onDidStartTaskProcess are equal to original', () => {
171+
return new Promise(async (resolve) => {
172172
const task = new Task({ type: 'testTask' }, TaskScope.Workspace, 'echo', 'testTask', new ShellExecution('echo', ['hello test']));
173173
let taskExecution: TaskExecution | undefined;
174174
const executeDoneEvent: EventEmitter<void> = new EventEmitter();
@@ -178,61 +178,31 @@ import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomEx
178178
disposable.dispose();
179179
});
180180
});
181-
182-
disposables.push(tasks.onDidStartTaskProcess(async (e) => {
183-
await taskExecutionShouldBeSet;
184-
if (taskExecution === undefined) {
185-
reject('taskExecution is still undefined when process started.');
186-
} else if (e.execution !== taskExecution) {
187-
reject('Unexpected task execution value in start process.');
188-
}
189-
}));
190-
191-
disposables.push(tasks.onDidEndTaskProcess(async (e) => {
192-
await taskExecutionShouldBeSet;
193-
if (taskExecution === undefined) {
194-
reject('taskExecution is still undefined when process ended.');
195-
} else if (e.execution === taskExecution) {
181+
let count = 2;
182+
const progressMade: EventEmitter<void> = new EventEmitter();
183+
let startSucceeded = false;
184+
let endSucceeded = false;
185+
disposables.push(progressMade.event(() => {
186+
count--;
187+
if ((count === 0) && startSucceeded && endSucceeded) {
196188
resolve();
197-
} else {
198-
reject('Unexpected task execution value in end process.');
199189
}
200190
}));
201191

202-
taskExecution = await tasks.executeTask(task);
203-
executeDoneEvent.fire();
204-
});
205-
});
206-
207-
test.skip('Execution from onDidStartTaskProcess is equal to original', () => {
208-
return new Promise(async (resolve, reject) => {
209-
const task = new Task({ type: 'testTask' }, TaskScope.Workspace, 'echo', 'testTask', new ShellExecution('echo', ['hello test']));
210-
let taskExecution: TaskExecution | undefined;
211-
const executeDoneEvent: EventEmitter<void> = new EventEmitter();
212-
const taskExecutionShouldBeSet: Promise<void> = new Promise(resolve => {
213-
const disposable = executeDoneEvent.event(() => {
214-
resolve();
215-
disposable.dispose();
216-
});
217-
});
218192

219193
disposables.push(tasks.onDidStartTaskProcess(async (e) => {
220194
await taskExecutionShouldBeSet;
221-
if (taskExecution === undefined) {
222-
reject('taskExecution is still undefined when process started.');
223-
} else if (e.execution === taskExecution) {
224-
resolve();
225-
} else {
226-
reject('Unexpected task execution value in start process.');
195+
if (e.execution === taskExecution) {
196+
startSucceeded = true;
197+
progressMade.fire();
227198
}
228199
}));
229200

230201
disposables.push(tasks.onDidEndTaskProcess(async (e) => {
231202
await taskExecutionShouldBeSet;
232-
if (taskExecution === undefined) {
233-
reject('taskExecution is still undefined when process ended.');
234-
} else if (e.execution !== taskExecution) {
235-
reject('Unexpected task execution value in end process.');
203+
if (e.execution === taskExecution) {
204+
endSucceeded = true;
205+
progressMade.fire();
236206
}
237207
}));
238208

0 commit comments

Comments
 (0)