Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Use EventEmitter2 in tests to throw an error whenever an event fires …
Browse files Browse the repository at this point in the history
…that does not have a handler registered
  • Loading branch information
Chris Clark committed May 19, 2015
1 parent f679dfc commit 94ef298
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"devDependencies": {
"assert-diff": "^0.0.4",
"coveralls": "^2.10.0",
"eventemitter2": "^0.4.14",
"istanbul": "^0.2.10",
"mocha": "^2.1.0",
"npm-shrinkwrap": "^5.3",
Expand Down
6 changes: 3 additions & 3 deletions test/balances-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,11 @@ suite('get balances', function() {
conn.send(fixtures.accountNotFoundResponse(message));
});

/* TODO: uncommenting this breaks *other* test cases
self.wss.once('request_account_lines', function(message, conn) {
assert(false, 'Should not request account lines');
assert.strictEqual(message.command, 'account_lines');
assert.strictEqual(message.account, addresses.VALID);
conn.send(fixtures.accountNotFoundResponse(message));
});
*/

self.app
.get(requestPath(addresses.VALID))
Expand Down
7 changes: 4 additions & 3 deletions test/payments-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,8 @@ suite('post payments', function() {
conn.send(fixtures.accountInfoResponse(message));
});

self.wss.once('request_submit', function(message, conn) {
// "on" instead of "once" because ripple-lib resubmits
self.wss.on('request_submit', function(message, conn) {
assert.strictEqual(message.command, 'submit');

conn.send(fixtures.rippledSubmitErrorResponse(message, {
Expand Down Expand Up @@ -969,7 +970,7 @@ suite('post payments', function() {
conn.send(fixtures.rippledSubcribeResponse(message));
});

self.wss.once('request_account_info', function(message, conn) {
self.wss.on('request_account_info', function(message, conn) {
assert.strictEqual(message.command, 'account_info');
assert.strictEqual(message.account, addresses.VALID);
conn.send(fixtures.accountInfoResponse(message));
Expand Down Expand Up @@ -1007,7 +1008,7 @@ suite('post payments', function() {
conn.send(fixtures.rippledSubcribeResponse(message));
});

self.wss.once('request_account_info', function(message, conn) {
self.wss.on('request_account_info', function(message, conn) {
assert.strictEqual(message.command, 'account_info');
assert.strictEqual(message.account, addresses.VALID);
conn.send(fixtures.accountInfoResponse(message));
Expand Down
19 changes: 19 additions & 0 deletions test/testutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var api = require('../server/api');
var apiFactory = require('../server/apifactory');
var version = require('../server/version');
var PRNGMock = require('./prngmock');
var EventEmitter2 = require('eventemitter2').EventEmitter2;

var LEDGER_OFFSET = 3;

Expand Down Expand Up @@ -58,6 +59,24 @@ function setup(done) {
self.db = api.db;

self.wss = new WSS({port: 5995});
_.assign(self.wss, EventEmitter2.prototype);

self.wss.onAny(function() {
if (self.wss.listeners(this.event).length === 0) {
throw new Error('Should not ' + this.event.replace(/_/g, ' '));
}
});

self.wss.on('listening', function() {});
self.wss.on('headers', function() {});
self.wss.on('connection/', function() {});
self.wss.on('request_subscribe', function(message) {
// always allow subscribing to account notifications
if (self.wss.listeners('request_subscribe').length <= 1) {
assert(message.accounts && message.accounts.length === 1);
assert(message.streams === undefined);
}
});

self.wss.once('connection', function(conn) {
conn.on('message', function(message) {
Expand Down

0 comments on commit 94ef298

Please sign in to comment.