diff --git a/packages/main/src/plugin/progress-impl.spec.ts b/packages/main/src/plugin/progress-impl.spec.ts index ec5cd99c29b75..376cb14dabc86 100644 --- a/packages/main/src/plugin/progress-impl.spec.ts +++ b/packages/main/src/plugin/progress-impl.spec.ts @@ -66,18 +66,15 @@ test('Should create a task and propagate the exception', async () => { const progress = new ProgressImpl(taskManager); - try { - await progress.withProgress({ location: ProgressLocation.TASK_WIDGET, title: 'My task' }, async () => { + await expect( + progress.withProgress({ location: ProgressLocation.TASK_WIDGET, title: 'My task' }, async () => { throw new Error('dummy error'); - }); - // Should NEVER be here. - expect(true).toBe(false); - } catch (e: unknown) { - expect((e as Error).message).toBe('dummy error'); - } + }), + ).rejects.toThrowError('dummy error'); expect(updateTaskMock).toHaveBeenCalledTimes(1); expect(updateTaskMock).toHaveBeenCalledWith({ + error: 'Error: dummy error', state: 'completed', status: 'failure', }); @@ -109,3 +106,26 @@ test('Should create a task and propagate the result', async () => { status: 'success', }); }); + +test('Should update the task name', async () => { + const createTaskMock = vi.fn(); + const updateTaskMock = vi.fn(); + const taskManager = { + createTask: createTaskMock, + updateTask: updateTaskMock, + } as unknown as TaskManager; + + createTaskMock.mockImplementation(() => ({})); + const progress = new ProgressImpl(taskManager); + + await progress.withProgress({ location: ProgressLocation.TASK_WIDGET, title: 'My task' }, async progress => { + progress.report({ message: 'New title' }); + }); + + expect(updateTaskMock).toHaveBeenCalledTimes(2); + expect(updateTaskMock).toHaveBeenLastCalledWith({ + name: 'New title', + state: 'completed', + status: 'success', + }); +}); diff --git a/packages/main/src/plugin/progress-impl.ts b/packages/main/src/plugin/progress-impl.ts index 5887fd0c2ce81..4d1d9fb7ae996 100644 --- a/packages/main/src/plugin/progress-impl.ts +++ b/packages/main/src/plugin/progress-impl.ts @@ -89,7 +89,7 @@ export class ProgressImpl { { report: value => { if (value.message) { - t.error = value.message; + t.name = value.message; } if (value.increment) { t.progress = value.increment; @@ -110,6 +110,7 @@ export class ProgressImpl { // Middleware to set to error the task t.status = 'failure'; t.state = 'completed'; + t.error = String(err); // We propagate the error to the caller, so it can handle it if needed throw err; })