Skip to content

Commit

Permalink
fix: message property used to update task name (podman-desktop#5731)
Browse files Browse the repository at this point in the history
* fix: message property used to update task name

Signed-off-by: axel7083 <[email protected]>

* Update packages/extension-api/src/extension-api.d.ts

Co-authored-by: Florent BENOIT <[email protected]>
Signed-off-by: axel7083 <[email protected]>

* test: removing useless void return

Signed-off-by: axel7083 <[email protected]>

* revert: remove docs

Signed-off-by: axel7083 <[email protected]>

* test: improve vitest usage

Signed-off-by: axel7083 <[email protected]>

---------

Signed-off-by: axel7083 <[email protected]>
Co-authored-by: Florent BENOIT <[email protected]>
  • Loading branch information
axel7083 and benoitf authored Jan 29, 2024
1 parent 8a823fe commit fd33d44
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
36 changes: 28 additions & 8 deletions packages/main/src/plugin/progress-impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
Expand Down Expand Up @@ -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<void>({ 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',
});
});
3 changes: 2 additions & 1 deletion packages/main/src/plugin/progress-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
})
Expand Down

0 comments on commit fd33d44

Please sign in to comment.