feat(@embark/testing): introduce proper request2 api for async/await

This commit is contained in:
Pascal Precht 2020-01-13 15:53:05 +01:00 committed by Iuri Matias
parent dc9171a1e7
commit c947517c0d
1 changed files with 12 additions and 1 deletions

View File

@ -40,7 +40,18 @@ class Events {
request2(cmd, ...args) {
assert(this.commandHandlers[cmd], `command handler for ${cmd} not registered`);
this.commandHandlers[cmd](...args);
return new Promise((resolve, reject) => {
args.push((err, ...res) => {
if (err) {
return reject(err);
}
if (res.length && res.length > 1) {
return resolve(res);
}
return resolve(res[0]);
});
this.commandHandlers[cmd](...args);
});
}
}