diff options
| -rw-r--r-- | app/lib/jsonrpc-ws-ipc.js | 4 | ||||
| -rw-r--r-- | test/ipc.spec.js | 20 |
2 files changed, 22 insertions, 2 deletions
diff --git a/app/lib/jsonrpc-ws-ipc.js b/app/lib/jsonrpc-ws-ipc.js index f3850c430c..3d028c5a23 100644 --- a/app/lib/jsonrpc-ws-ipc.js +++ b/app/lib/jsonrpc-ws-ipc.js @@ -74,14 +74,14 @@ export default class Ipc { this._sendTimeoutMillis = millis; } - on(event: string, listener: (any) => void) { + on(event: string, listener: (any) => void): Promise<*> { // We're currently not actually using the event parameter. // This is because we aren't sure if the backend will use // one subscription per event or one subscription per // event source. log.info('Adding a listener to', event); - this.send('event_subscribe') + return this.send('event_subscribe') .then(subscriptionId => this._subscriptions[subscriptionId] = listener); } diff --git a/test/ipc.spec.js b/test/ipc.spec.js index 43a17b4911..ae9c5ab815 100644 --- a/test/ipc.spec.js +++ b/test/ipc.spec.js @@ -69,6 +69,26 @@ describe('The IPC server', () => { expect(e.message).to.contain('timed out'); }); }); + + it('should route notifications', (done) => { + const { ws, ipc } = setupIpc(); + + const eventListener = (event) => { + try { + expect(event).to.equal('an event!'); + done(); + } catch (ex) { + done(ex); + } + }; + + ws.on('event_subscribe', (msg) => ws.replyOk(msg.id, 1)); + ipc.on('event', eventListener) + .then(() => { + ws.reply(jsonrpc.notification('event', {subscription:1, result: 'an event!'})); + }) + .catch((e) => done(e)); + }); }); function mockWebsocket() { |
