diff --git a/lib/passthrough-emitter.js b/lib/passthrough-emitter.js index 090417d85..70f4d8b49 100644 --- a/lib/passthrough-emitter.js +++ b/lib/passthrough-emitter.js @@ -1,16 +1,14 @@ 'use strict'; -const _ = require('lodash'), - AsyncEmitter = require('gemini-core').events.AsyncEmitter; +const _ = require('lodash'); +const AsyncEmitter = require('gemini-core').events.AsyncEmitter; -module.exports = class PassthroughEmitter extends AsyncEmitter { - // Allow to pass only one argument with event - emit(type, data) { - return super.emit(type, data); - } +const ASYNC_FLAG = 'async'; +const markAsAsync = (args) => !args.includes(ASYNC_FLAG) ? args.concat(ASYNC_FLAG) : args; - emitAndWait(type, data) { - return super.emitAndWait(type, data, {shouldWait: true}); +module.exports = class PassthroughEmitter extends AsyncEmitter { + emitAndWait(type, ...args) { + return super.emitAndWait(type, ...markAsAsync(args)); } /** @@ -24,11 +22,11 @@ module.exports = class PassthroughEmitter extends AsyncEmitter { return; } - emitter.on(event, function(data, opts) { - if (opts && opts.shouldWait) { - return this.emitAndWait(event, data); + emitter.on(event, function(...args) { + if (args.includes(ASYNC_FLAG)) { + return this.emitAndWait(event, ...args); } else { - this.emit(event, data); + this.emit(event, ...args); } }.bind(this)); } diff --git a/test/unit/passthrough-emitter.js b/test/unit/passthrough-emitter.js index c36bfd6b4..85983c09f 100644 --- a/test/unit/passthrough-emitter.js +++ b/test/unit/passthrough-emitter.js @@ -46,5 +46,17 @@ describe('PassthroughEmitter', () => { assert.equal(data, 'some-data'); }); }); + + it('should be able to pass multiple event arguments', () => { + runner.passthroughEvent(child, 'some-event'); + runner.on('some-event', function(...args) { + return `some-data ${args[0]} ${args[1]}`; + }); + + return child.emitAndWait('some-event', 'foo', 'bar') + .then((data) => { + assert.equal(data, `some-data foo bar`); + }); + }); });