From fd33d44d092506884731768d84596bab0f2dafb9 Mon Sep 17 00:00:00 2001 From: axel7083 <42176370+axel7083@users.noreply.github.com> Date: Mon, 29 Jan 2024 15:58:29 +0100 Subject: [PATCH] fix: message property used to update task name (#5731) * fix: message property used to update task name Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> * Update packages/extension-api/src/extension-api.d.ts Co-authored-by: Florent BENOIT Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> * test: removing useless void return Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> * revert: remove docs Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> * test: improve vitest usage Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> --------- Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> Co-authored-by: Florent BENOIT --- .../main/src/plugin/progress-impl.spec.ts | 36 ++++++++++++++----- packages/main/src/plugin/progress-impl.ts | 3 +- 2 files changed, 30 insertions(+), 9 deletions(-) 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; })