Skip to content

Commit

Permalink
feat(@embark/testing): introduce proper request2 api for async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
0x-r4bbit authored and iurimatias committed Jan 15, 2020
1 parent dc9171a commit c947517
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/utils/testing/src/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}

Expand Down

0 comments on commit c947517

Please sign in to comment.