From c947517c0d99c805be30917d9b3d813a5cce6436 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Mon, 13 Jan 2020 15:53:05 +0100 Subject: [PATCH] feat(@embark/testing): introduce proper request2 api for async/await --- packages/utils/testing/src/lib/events.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/utils/testing/src/lib/events.js b/packages/utils/testing/src/lib/events.js index b51df31b0..bd526a6db 100644 --- a/packages/utils/testing/src/lib/events.js +++ b/packages/utils/testing/src/lib/events.js @@ -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); + }); } }