Skip to content

Commit 6e1dc69

Browse files
committed
Add new method executeCmdWithProgress
Fix #417.
1 parent e0dc48f commit 6e1dc69

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/util/progress.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,18 @@ export class Progress {
4444
}, Promise.resolve());
4545
});
4646
}
47+
48+
static async execCmdWithProgress(title: string, cmd: string): Promise<any> {
49+
return new Promise(async (resolve, reject) => {
50+
await vscode.window.withProgress({
51+
cancellable: false,
52+
location: vscode.ProgressLocation.Notification,
53+
title},
54+
async (progress: vscode.Progress<{increment: number, message: string}>, token: vscode.CancellationToken) => {
55+
let result = await odoctl.getInstance().execute(cmd, process.cwd(), false);
56+
result.error ? reject(result.error) : resolve();
57+
}
58+
);
59+
});
60+
}
4761
}

test/util/progress.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,28 @@ suite('Progress Utility', () => {
6868
expect.fail('no error thrown');
6969
}
7070
});
71+
72+
test('execCmdWithProgress returned promice resolves in case of cmd finished sucessfully', () => {
73+
const error = new Error(errorMessage);
74+
execStub = sandbox.stub(OdoImpl.prototype, 'execute').resolves({error: undefined, stdout: '', stderr: ''});
75+
let e;
76+
Progress.execCmdWithProgress('title', 'cmd').catch(() => {
77+
expect.fail(true, false, 'returned promise should not be rejected');
78+
});
79+
});
80+
81+
test('execCmdWithProgress returned promice rejects in case of cmd finished with failure', async () => {
82+
const error = new Error(errorMessage);
83+
execStub = sandbox.stub(OdoImpl.prototype, 'execute').resolves({error, stdout: '', stderr: ''});
84+
let e;
85+
try {
86+
await Progress.execCmdWithProgress('title', 'cmd');
87+
} catch (err) {
88+
e = err;
89+
expect(err.message).equals(errorMessage);
90+
}
91+
if (!e) {
92+
expect.fail('no error thrown');
93+
}
94+
});
7195
});

0 commit comments

Comments
 (0)